#discord-bots

1 messages Β· Page 788 of 1

slate swan
#

How can I make such Buttons to Select something?

#

fr

cedar stream
wanton cipher
#

how do I pass in the request headers? is it a dict or...?

cedar stream
slate swan
slate swan
cedar stream
slate swan
#

how would you not know what lib youre using

#

quickest way is to check imports lmao

slate swan
cedar stream
cedar stream
#

Also you should consider reading docs etc. on pythob

slate swan
cedar stream
#

Python

final iron
#

You should learn python first

cedar stream
rocky trench
#

Please take a look at python basics first

#

U need to understand what we say when we help you

cedar stream
#

^^

slate swan
rocky trench
#

^^

cedar stream
#

Lucas πŸ˜‚

slate swan
cedar stream
#

Lmfao

normal moon
#

CheckFailure
im_a_failure = true

strong vessel
#

how to make the discord bot reply to message?

slate swan
rocky trench
#

Not always ctx )

slate swan
#

its a method

peak loom
#

I got this error the code is also attached.

rocky trench
#

But at your level I feel like u would use ctx at the start

strong vessel
#

await message.channel.send(reply)

final iron
slate swan
final iron
#

Fuc

rocky trench
strong vessel
#
if message.author == client.user:
    # Don't respond to ourselves
    return
# If reply to a message
if message.content.startswith('<@!{}>'.format(client.user.id)) or message.content.startswith('<@{}>'.format(client.user.id)):
    # Get the user's name
    user_name = message.author.name
    # Get the user's id
    user_id = message.author.id
    # Get the query
    query = message.content[len('<@!{}>'.format(client.user.id))+1:]
    # Get the reply
    reply = query(query, user_id, user_name)
    # Send the reply
    await message.channel.send(reply)
final iron
#

What is it

normal moon
peak loom
rocky trench
#

Its so much easier ngl

slate swan
cedar stream
#

Nvm

#

It’ s reaction remove

rocky trench
#

Its payload.user isn't it?

#

Long time ago that I used payload

peak loom
final iron
#

On reaction remove doesnt return a member

#

Or user

rocky trench
#

^^

peak loom
cedar stream
#

Only add

rocky trench
#

Like what event?

final iron
#

What event are you looking for?

cedar stream
#

There are all events in the docs

strong vessel
#

How to get when the user replies to the bot but without using the @ bot_name?

cedar stream
#

Under event reference

final iron
#

!d discord.on_raw_reaction_remove

unkempt canyonBOT
#

discord.on_raw_reaction_remove(payload)```
Called when a message has a reaction removed. Unlike [`on_reaction_remove()`](https://discordpy.readthedocs.io/en/master/api.html#discord.on_reaction_remove "discord.on_reaction_remove"), this is called regardless of the state of the internal message cache.

This requires [`Intents.reactions`](https://discordpy.readthedocs.io/en/master/api.html#discord.Intents.reactions "discord.Intents.reactions") to be enabled.
final iron
#

Whoever was trying to find it

cedar stream
peak loom
strong vessel
#

is that what the <@!{}> vs <@{}> means>

rocky trench
#

Eh I didn't even know these existed. Docs probably need update

final iron
rocky trench
cedar stream
strong vessel
#

what is the difference between the <@!{}> vs <@{}> ?

final iron
#

It straight up doesn't return a user id

strong vessel
rocky trench
#

Its very weird, I used it 5 months ago

strong vessel
#

how to return a message when the user replies to the bot directly but does not mention the bot

cedar stream
unkempt canyonBOT
#

discord.on_thread_update(before, after)```
Called whenever a thread is updated.

This requires [`Intents.guilds`](https://discordpy.readthedocs.io/en/master/api.html#discord.Intents.guilds "discord.Intents.guilds") to be enabled.

New in version 2.0.
rocky trench
#

Good to hear u found it

rocky trench
#

Dpy 2.0 indeed

slate swan
#

TYPE STRUCTURE EXAMPLE

User    <@USER_ID>    @split rivet
User (Nickname)    <@!USER_ID>    @split rivet
Channel    <#CHANNEL_ID>    [#103735883630395392](/guild/267624335836053506/channel/103735883630395392/)
Role    <@&ROLE_ID>    <@&165511591545143296>
Standard Emoji    Unicode Characters    πŸ’―
Custom Emoji    <:NAME:ID>    :mmLol:
Custom Emoji (Animated)    <a:NAME:ID>    :b1nzy:
Unix Timestamp    <t:TIMESTAMP>    <t:1618953630>
Unix Timestamp (Styled)    <t:TIMESTAMP:STYLE>    <t:1618953630:d>
cedar stream
#

!d discord.Message

unkempt canyonBOT
#

class discord.Message```
Represents a message from Discord.

x == y Checks if two messages are equal.

x != y Checks if two messages are not equal.

hash(x) Returns the message’s hash.
slate swan
rocky trench
slate swan
rocky trench
slate swan
strong vessel
#

!d discord.Message.content

unkempt canyonBOT
unkempt canyonBOT
#

The message that this message references. This is only applicable to messages of type MessageType.pins_add, crossposted messages created by a followed channel integration, or message replies.

New in version 1.5.

slate swan
#

guys I just started my coding heres my first code

#

its so fun

strong vessel
#

so if the user replies to the bot is that captured by the 'mention capturer'?

rocky trench
slate swan
slate swan
#

its just for your linter

rocky trench
slate swan
#

lol

rocky trench
#

That's what I meant

slate swan
#

i do

@bot.listen()
async def on_message(message: Message) -> None:

lol

strong vessel
# cedar stream ?
if message.author == client.user:
    # Don't respond to ourselves
    return
# If mention bot
if message.content.startswith('<@!{}>'.format(client.user.id)) or message.content.startswith('<@{}>'.format(client.user.id)):
    # Get the user's name
    user_name = message.author.name
    # Get the user's id
    user_id = message.author.id
    # Get the query
    query = message.content[len('<@!{}>'.format(client.user.id))+1:]
    # Get the reply
    reply = query(query, user_id, user_name)
    # Send the reply
    await message.channel.send(reply)

would the if mention bot part respond when a user replies to the bot but without explicitly mentioning the @bot name?

peak loom
slate swan
#

havent worked with payload

cedar stream
analog barn
#

hi so basically, when my bot starts, I want it to listen for cuss words in my wordlist and remove them, but I don't know how to get my bot to listen for messages outside of my prefix. Can I get some help?

peak loom
slate swan
#

just check the content

analog barn
#

so wait

unkempt canyonBOT
#
I don't think so.

No documentation found for the requested symbol.

cedar stream
#

@final iron

slate swan
#

!d discord.on_message

unkempt canyonBOT
#

discord.on_message(message)```
Called when a [`Message`](https://discordpy.readthedocs.io/en/master/api.html#discord.Message "discord.Message") is created and sent.

This requires [`Intents.messages`](https://discordpy.readthedocs.io/en/master/api.html#discord.Intents.messages "discord.Intents.messages") to be enabled.

Warning

Your bot’s own messages and private messages are sent through this event. This can lead cases of β€˜recursion’ depending on how your bot was programmed. If you want the bot to not reply to itself, consider checking the user IDs. Note that [`Bot`](https://discordpy.readthedocs.io/en/master/ext/commands/api.html#discord.ext.commands.Bot "discord.ext.commands.Bot") does not have this problem.
cedar stream
#

Ty

slate swan
#

Client has it aswell

rocky trench
#

And also try to use @bot.listen("on_message")

#

And not the event. The event can block your code

slate swan
analog barn
#
@bot.event()
async def on_message(ctx):
  if ctx in wordlist
    await #do smth
cedar stream
analog barn
#

right?

rocky trench
analog barn
#

ik bad python formatting

analog barn
#

just let it be for now

#

hm?

rocky trench
#

@bot.event doesn't need brackets either

analog barn
#

OH okay yeah cause its not a command

#

i see

rocky trench
#

^^

slate swan
#

or ctx.content since the message obj is context cuz of arg naming

analog barn
#

i make that error so much πŸ˜…

slate swan
#

but its not correct.

#

only commands have context not events

rocky trench
#

Or you can use

#

For word in words:
If word in message.content: do something

slate swan
#

!d discord.ext.commands.Context

unkempt canyonBOT
#
class discord.ext.commands.Context(*, message, bot, view, args=..., kwargs=..., prefix=None, command=None, invoked_with=None, invoked_parents=..., invoked_subcommand=None, ...)```
Represents the context in which a command is being invoked under.

This class contains a lot of meta data to help you understand more about the invocation context. This class is not created manually and is instead passed around to commands as the first parameter.

This class implements the [`Messageable`](https://discordpy.readthedocs.io/en/master/api.html#discord.abc.Messageable "discord.abc.Messageable") ABC.
analog barn
#
@bot.event()
async def on_message():
  if message.content in wordlist:
    await #do smth

rocky trench
#

Don't mind indents, mobile

analog barn
#

correct?

analog barn
#

what

#

okay

slate swan
rocky trench
#

Please use @bot.listen("on_message")

#

Its the same as ur event, just doesn't block ur code

slate swan
frank tartan
#

How can I search the author for any role in a list? (role names are in the list, please dont tell me to change them to objects)

rocky trench
analog barn
#
@bot.listen("on_message")
async def on_message(message):
  if message.content in wordlist:
    await #do smth

#

right?

slate swan
rocky trench
#

U can rename async def to whatever u want

#

Instead of on_message

slate swan
#

no

#

its on_message

rocky trench
analog barn
#

okay how about i just keep it

rocky trench
analog barn
#

let me try out both solutions

#

and see what works best for me

slate swan
rocky trench
frank tartan
#

How can I search the author for any role in a list? (role names are in the list, please dont tell me to change them to objects)

slate swan
rocky trench
slate swan
rocky trench
#

Take a look at GitHubπŸ˜‚

cedar stream
#

Just do @command.slash_command

#

In cog

slate swan
frank tartan
# rocky trench Author for any role?..

uhh not really... let me try to be more clear.

Person1: !roleCheck

bot will respond with yes if person1 has any role thats in the list called roleList.
otherwise, bot will respond with no.

roleList has role names, please dont tell me to change them to objects

cedar stream
#

Bro pls

slate swan
#

!d disnake.ext.commands.Bot.test_guilds

unkempt canyonBOT
#

The list of IDs of the guilds where you’re going to test your app commands. Defaults to None, which means global registration of commands across all guilds.

New in version 2.1.

cedar stream
#

Then do @bot.slash_command

cedar stream
slate swan
cedar stream
cedar stream
#

Read

#

The link

slate swan
#

or then youll have to wait 1hour so the slash commands registers globally

frank tartan
frank tartan
rocky trench
slate swan
#

why are yall being so aggressive smh?

rocky trench
#

and need to give them a name

cedar stream
#

Read what that is

frank tartan
rocky trench
#

well if u got that working, u can figure it out urself right?

cedar stream
#

Lmao if you click the link and read, I wont need to explain it

frank tartan
cedar stream
#

Ik u know what they are

rocky trench
#

Send ur script please.

frank tartan
# slate swan ctx.author.roles?

i tried that in

if author.roles in info.roleList:
  await ctx.reply("yes")
else:
  await ctx.reply("no")

but it says no even if they have the role

rocky trench
#

member.roles is good enough

#

anyway, did u set a typehint at member and = None?

slate swan
frank tartan
cedar stream
#

Decorator is @bot.slash_command but for slash commands u need to set test guilds otherwise it takes up to an hour to register them, also u need application.commands scope

slate swan
#

context

#

i need more context

rocky trench
#

Depends on the argument, mb

cedar stream
#

Wdym u cant use it

frank tartan
slate swan
rocky trench
cedar stream
#

Try self.slash_command πŸ€·πŸΌβ€β™‚οΈ

slate swan
#

@self.slash_command

#

since self is the Bot class i suppose its that

#

wdym?

cedar stream
#

Cus ur inside class

slate swan
#

self is a parameter that accesses the objs in a class

cedar stream
#

😭

cedar stream
slate swan
#

right

#

tbh i would make it in a cog

frank tartan
slate swan
#

yes

#

yes

rocky trench
#

Please stop helping if you don't know the answer

slate swan
#

that is so

rocky trench
#

Who even thinks of self in their command type

slate swan
#

i do know?i just never have done that?

rocky trench
#

U literally countered ur own argument in 1 sentence

slate swan
boreal ravine
slate swan
#

we dont talk about those humans lmao

#

made different

boreal ravine
#

whats your error/issue?

slate swan
#

hes trying to make a slash command in a Bot subclass

#

which is a bad idea aka you should make a cog

#
@bot.slash_command(description="Responds with 'World'")
async def hello(inter):
    await inter.response.send_message("World")
#

ye

slate swan
rocky trench
#

And bc u didn't even understand that, I had to say typing time

boreal ravine
#

Ik python was made in c but whats the difference between cpython and python

slate swan
#

it wont raise an error like: "not true typehint"

rocky trench
rocky trench
#

Then why u say that I said it affects run time? bruh

rocky trench
#

Where?

slate swan
rocky trench
#

Reply to my message right now

slate swan
#

scroll

rocky trench
#

I said it affects coding time

#

Coding is not run time facepalm_pika

rocky trench
boreal ravine
#

well this is not possible since you'd need to access self to make the slash command

slate swan
rocky trench
#

Ok? Is that saying it affects runtime?

#

I don't get you mate.

slate swan
#

bruh

rocky trench
#

Quote me right now that I said it affected run time?

#

Jesus kid.

daring olive
#

guys

#

take 3 steps back each

rocky trench
#

No, for real. He is spreading false information

#

Im just trying to help

slate swan
final iron
outer flint
#

have there already been migration guide for when discord.py will shut down? thinku

boreal ravine
#

make it outside the class ```py
bot = Application()

@bot.slash_command()
async def my_slash():
...

daring olive
rocky trench
rocky trench
slate swan
rocky trench
#

Imma head to help channels rq my brain can't take this

final iron
frank tartan
#

ok, I have an idea on how I can do what I want, but how do I get the role names? (or does ctx.author.roles give the role names?)

final iron
#

!d discord.Member.roles

unkempt canyonBOT
#

property roles: List[Role]```
A [`list`](https://docs.python.org/3/library/stdtypes.html#list "(in Python v3.9)") of [`Role`](https://discordpy.readthedocs.io/en/master/api.html#discord.Role "discord.Role") that the member belongs to. Note that the first element of this list is always the default [β€˜@everyone](mailto:'%40everyone)’ role.

These roles are sorted by their position in the role hierarchy.
final iron
boreal ravine
#

you're using disnake right?

slate swan
frank tartan
rocky trench
daring olive
rocky trench
#

This is what most people use.

rocky trench
daring olive
#

!silence

unkempt canyonBOT
#

βœ… silenced current channel for 10 minute(s).

daring olive
#

the level of maturity in this channel needs to increase by about 50%
if you feel you cannot do that, i will ask that you close discord and walk away
when it gets to this level of hostility, it doesn't matter who is right or wrong anymore
you've lost all opportunity of having a civil discourse at this point

#

so after the channel is unsilenced, either you move on to another discord-bot related topic, or you don't participate (for now)

#

!unsilence

unkempt canyonBOT
#

βœ… unsilenced current channel.

final iron
final iron
#

Aren't you using disnake? Disnake already has slash command support

boreal ravine
rocky trench
slate swan
#

disnake has slash command support.

rocky trench
#

Let me take a look for disnake

boreal ravine
#

i think Danny recommends slash_util idk

slate swan
rocky trench
slate swan
#

check

#

why use a third party lib if your lib youre using has support for it?

boreal ravine
#

Β―\_(ツ)_/Β―

final iron
rocky trench
#

Its a pretty good explanation. Wish discord.py didn't get discontinued

final iron
#

I'm pretty sure everyone didn't want dpy to get discontinued

rocky trench
#

Is there a big difference between discord and disnake? If not, I might switch.

slate swan
#

and it says "slash command support for dpy 2.0"

slate swan
#

just names and the new features

final iron
#

And you're fine

brave ravine
#
icon = str(ctx.guild.icon_url)
    await ctx.send(icon)``` this sends  a blank picture with
rocky trench
#

So the only actual advantage that would give me are / commands?

final iron
#

Also getch

rocky trench
#

get channel

final iron
#

Probably some other stuff I'm missing

rocky trench
#

Alright, don't know if it's worth it tho

slate swan
rocky trench
#

2.0

brave ravine
final iron
slate swan
rocky trench
#

Don't think I am

slate swan
final iron
rocky trench
#

It isn't indeed

final iron
#

What does getching support

slate swan
#

or switch to better lib hikari

final iron
#

Like channels, guilds, members

#

What can I getch?

slate swan
#

you cant getch users or messages users idk why its not implemented

final iron
slate swan
boreal ravine
#

is hikari a fork?

slate swan
boreal ravine
final iron
unkempt canyonBOT
boreal ravine
#

im pretty sure you use disnake

slate swan
boreal ravine
#

yeah

#

djs gets updated everyday

slate swan
#

does it what features does it have better than dpy

final iron
#

What's javascripts equivalent to pypi

#

Do they have one?

boreal ravine
#

node package manager

slate swan
#

been told the comunity are a bit toxic not sure if its true

boreal ravine
slate swan
#

why so?

boreal ravine
#

idk

slate swan
#

thats kinda not helpful

#

damn

#

so its just a stackoverflow redirect

#

yes

#

message intents will be priviledge which verified bot devs have to ask for the intent or they cannot have the intent if your bot is unverified you can still have it

#

such a change as devs say its hard to get intents thats why slash commands are a thing since they cant see what the message contains do the content of it

#

so they cannot see the prefix and thats why slash commands are being used

#

yep

final iron
#

If the message content intent is going to be hard to get doesn't that mean custom commands are dead?

slate swan
#

you can only get it if you hsve a good reason for it

final iron
#

I guess something like /tag <tag> will work but its not really a custom command

left crater
#
    channel = bot.get_channel(699577970117050399)
    messages = await channel.history(limit=None).flatten()
    for p in messages:
        print(p.attachments)``` this code gets all the urls but it also gives me a bunch of extra stuff that i dont want. Can I get only the urls
final iron
#

Fuck Discord's handling of developers

slate swan
final iron
slate swan
#

Can I have Name arg in the parentheses of @ commands.Cog.listener()?

analog barn
#

hey I need your help again.
I have a wordlist with cuss words. My code deletes those cuss words quickly and efficiently and I'm happy with that I have.

Here's my problem though...
If someone sends links, or images, it gets deleted even though it can't be run through the wordlist or the wordlist has nothing of that message content value.

So I need to make it stop deleting images and media other then text somehow...

My second problem is users can bypass this filter by putting their cuss word in a sentence... so I need to find a way to check if the word is IN the phrase or message instead of checking the first word and deleting it if it matches...

third problem is that users can bypass this filter by putting it in uppercase. so I don't know for sure how exactly i'd do that, (i'm pretty sure i use message.content.toLower() or something along those lines, however, I'm just checking up on that one...

can I get some help?

slate swan
#

!d discord.ext.commands.Cog.listener

unkempt canyonBOT
#

classmethod listener(name=...)```
A decorator that marks a function as a listener.

This is the cog equivalent of [`Bot.listen()`](https://discordpy.readthedocs.io/en/master/ext/commands/api.html#discord.ext.commands.Bot.listen "discord.ext.commands.Bot.listen").
slate swan
#

yep

slate swan
# slate swan probably

It says β€œTypeError listener() got an unexpected keyword arg β€œName””

analog barn
#

...anyone-?

slate swan
slate swan
slate swan
#

@commands.Cog.listener(Name = 'on_message', description = 'react with message')
async def on_message(self, message):
if message.author == self.bot.user:
return

slate swan
#

or remove the whole arg

#

because the function is named on msg

slate swan
#

The actual Name arg is not on_message

#

ic

#

no need for it tbh

dry kelp
#

How do i get the before emoji asset?

frank tartan
#

how do I make a list of role objects? I tried

roleList = [<Role id=926477597355962401 name='role1'>, <Role id=926477597355962401 name='role2'>]

but i get a invalid syntax error

analog barn
#

uh hey

@dasm.listen("on_message")
async def on_message(ctx, message):
    msg = str(message.content).lower()
    print(msg)
    if msg in wordlist:
        await message.delete()
        await ctx.send("Dont use that word!")
    await ctx.process_commands(message)

after reformatting my code a little bit, I am receiving errors.
am I blind? or is message passed in-

slate swan
#

only message can be used

green bluff
#
async def get_bank_data():
    with open ("bank.json",'r') as f:
        users = json.load(f)
    return users 


@client.command()

async def beg(ctx):    
    user = ctx.author
    await open_account(user)
    users = await get_bank_data(user.id)
    
        
    earnings = random.randint(1,1000)
    users[str(user.id)]['money'] += earnings
    await ctx.send(earnings)
    with open('bank.json', 'w') as f:
        json.dump(users,f)

async def open_account(user):
    with open ("bank.json",'r') as f:
        users = json.load(f)
    
    if str(user.id) in users:
        return False
    else:
        users[str(user.id)] = {}
        users[str(user.id)]['money'] = 0
        users[str(user.id)]['bank'] = 0
        users[str(user.id)]['inventory'] = []
        users[str(user.id)]['lootchest'] = 0

    with open ("bank.json",'w') as f:
        json.dump(users,f)
        return True
analog barn
#

also, I want it to delete the message if it finds there is a bad word in the phrase too...

green bluff
analog barn
#

but after testing, I can bypass my filter by putting my cuss word into a sentence.

slate swan
analog barn
#

fixed

#

but again, it doesn't work if I put my cuss in a sentence.

slate swan
#
  1. message.content is a string why make it a string
analog barn
#

i was testing smth

#

OH

slate swan
#

you are checking ```py
if "a long sentence you send to discord" in ["list" ,"of","words"]:

analog barn
#

yes thats why
it's because i'm formatting message.content to lowercase

slate swan
analog barn
slate swan
green raptor
# analog barn

You don't need to convert message.content to a string. You're checking the entire message for those words which will not work unless its just that word alone.

slate swan
#

!e print(" okimii is cool" in ["okimii"])

unkempt canyonBOT
#

@slate swan :white_check_mark: Your eval job has completed with return code 0.

False
slate swan
#

^^ it will fail

analog barn
slate swan
#

use any and iterate inside the list of words

analog barn
#

so by formatting the cuss word, it can check for it properly

#

for example

frank tartan
#

how do I make a list of role objects? I tried

roleList = [<Role id=926477597355962401 name='role1'>, <Role id=926477597355962401 name='role2'>]

but i get a invalid syntax error

green raptor
#
if any([m for m in msg.split() if m in cuswords]):
  ...
#

You can still do that with the following:

message.content.lower()
green raptor
#

There are much more pythonic ways of doing the first, but that should work lol.

frank tartan
slate swan
#

!e ```py
sentence = "okimii is cool"
listofwordss = ["okimii"]
print(any(word for word in sentence.lower().split() if word in listofwordss))

unkempt canyonBOT
#

@slate swan :white_check_mark: Your eval job has completed with return code 0.

True
slate swan
#

and here's how it works.

final iron
slate swan
green raptor
#

I forgot about the good ol "any" built-in πŸ˜†

frank tartan
#

but i cant even run my code anymore

#

cuz i get a syntac error

final iron
frank tartan
#

ok, lemme explain what I want to do, cuz idk how that would help me.

roleList would have 28-30 roles.
when someone runs
!check <@ user>
if they have one of the roles, I want it to say the user has the <role> role.
if they dont, I want it to say no

i hope that makes sense

green raptor
# green bluff

Replace line 1 with:

def get_bank_data(uid: int) -> dict:

Replace:

users = await get_bank_data(user.id)```
With:
```python
users = get_bank_data(user.id)```
frank tartan
final iron
green bluff
#

?

slate swan
#

@green raptor btw you can just do py for code blocks no need for python (its faster)

final iron
slate swan
#

its not for storing data and its used for formatting data

final iron
green bluff
#

what else do u recommend

slate swan
#

if you make a request to an api MOST apis respond with json formatted data

slate swan
#

sqlite

final iron
slate swan
#

but just the async bridge aiosqlite

green bluff
#

ok lemme look up tutorials

green raptor
green bluff
#

but i think i should use sqlite

green raptor
green bluff
#

and just keep brackets

green raptor
#

If you're not going to use it in the get_bank_data function, yes.

green bluff
#

yes k

#

also uid

green raptor
#

And remove the await

green bluff
#

is not defined

green raptor
#

and remove the uid

pliant gulch
#

You shouldn't make get_bank_data a coroutine if it isn't even doing any asynchronous operations

green raptor
#

^

green bluff
pliant gulch
#

with

pliant gulch
#

Your functions are still coroutines

#

Oh wait you did change it

#

Did you save it??

green bluff
#

yes pretty sure lemme re run

echo wasp
#

Ok I tried it failed how do I mention q member that joined?

green bluff
#

doesnt work

green raptor
#

It tends to be the simplest mistakes.

echo wasp
green bluff
#

no ()

bold surge
#

^

green bluff
#

just member.mention

bold surge
#

and it should be in an f-string

pliant gulch
#

Can you add a print into your setup function where the OnReady cog is

echo wasp
#

Good to know

#

It is

green bluff
#

f"{member.mention}"

#

its still

#

qcourutine

bold surge
pliant gulch
#

So your cog_loader code inside of your main file didn't call load_extension on the on ready file

green bluff
bold surge
#

a discord bot developer

pliant gulch
green bluff
slate swan
pliant gulch
#

If your cog_loader method found the file it would've called load_extension and thus would have ran the setup function inside of that file

#

but you say it never printed anything in the setup function, thus the cog_loader logic didn't work

bold surge
#

i dont think thats the error...

#

shouldnt it be @commands.Cog.listener

#

as its in a cog

pliant gulch
bold surge
#

thats not needed...

pliant gulch
#

Yea, not-needed but not the error

bold surge
#

a lot of the code is over-complicated...

#

you cant import Bot from disnake.ext

#

you can only import Client which is not being used

compact ruin
#

Guys does anyone know how to place strings in sqlite data

pliant gulch
#

If they couldn't import it they wouldve gotten an import error πŸ‘οΈ πŸ‘οΈ

#

The issue is that the cog_loader method couldn't find the file, thus never calls load_extension

#

Otherwise something would have been printed

#

These nitpicks aren't helping at all

bold surge
slate swan
#

and yes ^

pliant gulch
#

πŸ‘

compact ruin
#
value = ("Hello")
db = sqlite3.connect('data/test.sqlite')
    cursor = db.cursor()
    cursor.execute(f"SELECT * from main WHERE member_id = {user.id}")
    result = cursor.fetchone()


    sql = f"UPDATE main SET String = ? WHERE member_id = ?"
    val = (value, user.id)

    cursor.execute(sql, val)
    db.commit()
    cursor.close()
    db.close()

The database saves the value as Hello and not "Hello" i was wondering how to save it as "Hello" with the strings

compact ruin
bold surge
slate swan
bold surge
#

use aiosqlite and not sqlite3...

#

sqlite3 is not async and discord.py is which will cause runtime errors

#

aiosqlite is async so your code will function propperly

#

also shouldnt it be a .db file?

strong vessel
unkempt canyonBOT
#

SQL & f-strings
Don't use f-strings (f"") or other forms of "string interpolation" (%, +, .format) to inject data into a SQL query. It is an endless source of bugs and syntax errors. Additionally, in user-facing applications, it presents a major security risk via SQL injection.

Your database library should support "query parameters". A query parameter is a placeholder that you put in the SQL query. When the query is executed, you provide data to the database library, and the library inserts the data into the query for you, safely.

For example, the sqlite3 package supports using ? as a placeholder:

query = "SELECT * FROM stocks WHERE symbol = ?;"
params = ("RHAT",)
db.execute(query, params)

Note: Different database libraries support different placeholder styles, e.g. %s and $1. Consult your library's documentation for details.

See Also
β€’ Extended Example with SQLite (search for "Instead, use the DB-API's parameter substitution")
β€’ PEP-249 - A specification of how database libraries in Python should work

pliant gulch
#

You def want to avoid the f-string inside of your first execute call

#

Switch it for parameters

slate swan
#

hes using place holders which sql doesnt execute the SQL statements

#

or am i wrong?

pliant gulch
#

That opens a lot of vulnerabilities

slate swan
slate swan
analog barn
#

I'm back with another peculiar problem.

@dasm.listen("on_message")
async def on_message(message):
    msg = message.content
    if say_delete_msg == True:
        if any(word for word in msg.lower().split() if word in wordlist):
            print(f"DELETED: ('{msg}') from ('{message.author}') at {datetime.now()}")
            await message.author.send(f"Hey! We just deleted your message. `{msg}` at `{datetime.now()}`\n\nThis is because the content you've sent matched with our `Profanity Wordlist`\n\nBelieve this was a fault? type `.pardonme (your sentence)` so that we can check out what went wrong.")
            await message.delete()
    else:
        if any(word for word in msg.lower().split() if word in wordlist):
            await message.author.send(f"Hey! We just deleted your message. `{msg}` at `{datetime.now()}`\n\nThis is because the content you've sent matched with our `Profanity Wordlist`\n\nBelieve this was a fault? type `.pardonme (your sentence)` so that we can check out what went wrong.")
            await message.delete()

This is now my filter.
which works? however, BECAUSE I am also trying to dm this user, the message is deleted and returns this big chunk of an error:

#
Ignoring exception in on_message
Traceback (most recent call last):
  File 
"C:\Users\Ethan\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\http.py", line 248, in request
    raise Forbidden(r, data)
discord.errors.Forbidden: 403 Forbidden (error code: 50003): Cannot execute action on a DM channel
Ignoring exception in on_message
Traceback (most recent call last):
  File "C:\Users\Ethan\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\client.py", line 343, in _run_event
    await coro(*args, **kwargs)
  File "C:\Users\Ethan\Desktop\dmod killer\blob\dasm\main.py", line 128, in on_message
    await message.author.send(f"Hey! We just deleted your message. `{msg}` at `{datetime.now()}`\n\nThis is because the content you've sent matched with our `Profanity Wordlist`\n\nBelieve this was a fault? type `.pardonme (your sentence)` so that we can check out what went wrong.")     
  File "C:\Users\Ethan\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\abc.py", line 1013, in send
    channel = await self._get_channel()
  File "C:\Users\Ethan\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\user.py", line 722, in _get_channel
    ch = await self.create_dm()
  File "C:\Users\Ethan\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\user.py", line 764, in create_dm
    data = await state.http.start_private_message(self.id)
  File "C:\Users\Ethan\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\http.py", line 254, in request
    raise HTTPException(r, data)
discord.errors.HTTPException: 400 Bad Request (error code: 50007): Cannot send messages to this 
user
#

now at the bottom, it says it cannot send messages to me, however...

final iron
#

Are your dms off?

analog barn
#

my dms are on and server dms are on

#

it's just my friend requests that are off

#

oh... i think i'm understanding?

#

so what it's doing is since it's detecting EVERYONE's message, it is deleting it's own because it's telling the user what they said wrong

#

and of course, what they said wrong is against the wordlist

#

so it removes its own message

#

how do i check if the user isn't a bot again-?

#

i know user.bot works, but I don't really know how to apply it to my code-

#

i might've solved it

#

wait...

#

and with that, I've fixed ONE of my issues

#
@dasm.listen("on_message")
async def on_message(message):
    msg = message.content
    if say_delete_msg == True:
        if any(word for word in msg.lower().split() if word in wordlist):
            if not message.author.bot:
                print(f"DELETED: ('{msg}') from ('{message.author}') at {datetime.now()}")
                await message.author.send(f"Hey! We just deleted your message. `{msg}` at `{datetime.now()}`\n\nThis is because the content you've sent matched with our `Profanity Wordlist`\n\nBelieve this was a fault? type `.pardonme (your sentence)` so that we can check out what went wrong.")
                await message.delete()
            else:
                print(colored(f"I was about to delete my own message... but I saved myself :) {datetime.now()}", "red"))
    else:
        if any(word for word in msg.lower().split() if word in wordlist):
            await message.author.send(f"Hey! We just deleted your message. `{msg}` at `{datetime.now()}`\n\nThis is because the content you've sent matched with our `Profanity Wordlist`\n\nBelieve this was a fault? type `.pardonme (your sentence)` so that we can check out what went wrong.")
            await message.delete()
#

adding this quick little fix makes it not remove it's own message

#

however, it's still returning a 404 not found error

#

with unknown message

#

so it's working with sending what it deleted

#

hmm

#

hm?

#

I thought it would be better this way since this is a cuss filter

#

OH

#

you mean that

#

okay hold on...

#

so what is the difference between getting by id

unkempt canyonBOT
#

await fetch_message(id, /)```
This function is a [*coroutine*](https://docs.python.org/3/library/asyncio-task.html#coroutine).

Retrieves a single [`Message`](https://discordpy.readthedocs.io/en/master/api.html#discord.Message "discord.Message") from the destination.
analog barn
#

and the message content

#

oh..

#

okay

#

so the idea behind fetching the message id works better with deleting the message, sure...

#

but what I'm doing here, is getting the content, and looking to see if the word is in my wordlist

#

so you could not format the message to lower for example if it was fetched by id

#

hm

#

you told me to replace my variable msg with your code

#

unless you didn't know i had a variable with msg already

#

haahhaha

#

oh haha

#

easy mistake lol

#

sorry for all of that

#

haha πŸ˜…

#

yep dw haha

#

the error remains presented even after the changes you suggested

#

@dasm.listen("on_message")

async def on_message(message):

    msg = message.content

    message_to_delete = await message.channel.fetch_message(message.id)

    if say_delete_msg == True:

        if any(word for word in msg.lower().split() if word in wordlist):

            if not message.author.bot:

                await message_to_delete.delete()

                print(f"DELETED: ('{msg}') from ('{message.author}') at {datetime.now()}")

                await message.author.send(f"Hey! We just deleted your message. `{msg}` at `{datetime.now()}`\n\nThis is because the content you've sent matched with our `Profanity Wordlist`\n\nBelieve this was a fault? type `.pardonme (your sentence)` so that we can check out what went wrong.")

                
            else:

                print(colored(f"I was about to delete my own message... but I saved myself :) {datetime.now()}", "red"))

    else:

        if any(word for word in msg.lower().split() if word in wordlist):

           if not message.author.bot:

                await message_to_delete.delete()

                await message.author.send(f"Hey! We just deleted your message. `{msg}` at `{datetime.now()}`\n\nThis is because the content you've sent matched with our `Profanity Wordlist`\n\nBelieve this was a fault? type `.pardonme (your sentence)` so that we can check out what went wrong.")

                

i've spaced out the messages to make it easier to read

#

because I could barely read it without

#

but those spaces aren't in the real code

#

no, i reverted the changes you've suggested.

#

because they didn't work

#

(sorry)

#

sure!

#

i've edited the message

final iron
#

Why do you have your Bot constructor variable called dasm

analog barn
#

because everytime I make my discord bot

#

i name that variable my bot's name

final iron
#

It's bad practice

native wedge
#

Whats better? SQL or MongoDB

analog barn
#

i'm going to keep the habit. I understand that is bad practice but that is how I go about things and it causes no difference to how my code works.

analog barn
#

the whole code would exceed the message character limit on discord

final iron
analog barn
#
# SETTINGS
bot_debug = False
say_delete_msg = True
final iron
#

If you're every going to work with a team, building these bad practices are going to bite you in the ass later on

unkempt canyonBOT
#

Pasting large amounts of code

If your code is too long to fit in a codeblock in discord, you can paste your code here:
https://paste.pythondiscord.com/

After pasting your code, save it by clicking the floppy disk icon in the top right, or by typing ctrl + S. After doing that, the URL should change. Copy the URL and post it here so others can see it.

slim ibex
analog barn
#

got it

native wedge
#

Could I use JSON as like a config?

final iron
slim ibex
#

to store secrets and stuff?

#

i would use a .env file

final iron
#

I need to check out yaml

slim ibex
#

yaml is pog

final iron
#

I've been hearing people talk about it

#

I have no idea what it is

slim ibex
#

its because its used for github actions

#

its a markup language

analog barn
#

don't mind the imports, I am importing things I am sure I will need in the future.

final iron
#
*abcdef
12345
#

Cool

analog barn
final iron
analog barn
#

okay,

#

on command, this will delete the user command
(i forgot to add a prefix check so maybe it IS causing the issue)

#

and of course if debug is on, it will send ait deleted debug message saying what message and its attributes and such

slim ibex
analog barn
#

or ill just add a prefix check..?

#

okay brb

final iron
slim ibex
#

mhmm

#
 doe: "a deer, a female deer"
 ray: "a drop of golden sun"
 pi: 3.14159
 xmas: true
 french-hens: 3
 calling-birds:
   - huey
   - dewey
   - louie
   - fred
 xmas-fifth-day:
   calling-birds: four
   french-hens: 3
   golden-rings: 5
   partridges:
     count: 1
     location: "a pear tree"
   turtle-doves: two
analog barn
#

pretty sure I did that right

#

woah

#

wait hold on

slim ibex
#

why global

#

and instead of a bare except block, do except Exception as e at the least

final iron
#

Don't use a bare exception block

final iron
#

Or else you'll be getting a visit from me...

slim ibex
analog barn
analog barn
final iron
#

Using a bare exception block is a no no in the eyes of pep8

slim ibex
#

ik

#

but atleast its something

#

you can print the exception

#

^

#

what error would the command raise if there was one

#

exception*

analog barn
#

all it does is return the error if it can't process the stuff in the try block

#

if there is an error

slim ibex
#

but you pass the except block?

#

^

analog barn
#

hold on

final iron
#

You want to do something like this: except asyncio.TimeoutError

analog barn
#

see it doesnt give errors

final iron
#

Notice how I'm catching the specific error

analog barn
#

but removing the on command thing

final iron
#

And not using a bare exception block

analog barn
#

removing the on command thing doesn't stop it from removing the message

#

actually

#

it stops returning the errors all together

#

it removes the message as it did the whole time

#

it shows i get a dm from the bot

#

but the message gets deleted instantly

#

and no error is raised

#
await message.author.send(f"Hey! We just deleted your message. `{msg}` at `{datetime.now()}`\n\nThis is because the content you've sent matched with our `Profanity Wordlist`\n\nBelieve this was a fault? type `.pardonme (your sentence)` so that we can check out what went wrong.")
#
@dasm.listen("on_message")
async def on_message(message):
    msg = message.content
    if say_delete_msg == True:
        if any(word for word in msg.lower().split() if word in wordlist):
            if not message.author.bot:
                await message.delete()
                print(f"DELETED: ('{msg}') from ('{message.author}') at {datetime.now()}")
                await message.author.send(f"Hey! We just deleted your message. `{msg}` at `{datetime.now()}`\n\nThis is because the content you've sent matched with our `Profanity Wordlist`\n\nBelieve this was a fault? type `.pardonme (your sentence)` so that we can check out what went wrong.")
                
            else:
                print(colored(f"I was about to delete my own message... but I saved myself :) {datetime.now()}", "red"))
    else:
        if any(word for word in msg.lower().split() if word in wordlist):
           if not message.author.bot:
                await message.author.send(f"Hey! We just deleted your message. `{msg}` at `{datetime.now()}`\n\nThis is because the content you've sent matched with our `Profanity Wordlist`\n\nBelieve this was a fault? type `.pardonme (your sentence)` so that we can check out what went wrong.")
                await message.delete()
#

exactly what you think it does

slim ibex
#

weat

#

lmao

analog barn
#
@dasm.event
async def on_command_error(et, error):
    try:
        await et.message.delete()
    except:
        pass
    if isinstance(error, commands.CommandNotFound):
        print_e(f"Unknown command: {error}")
    elif isinstance(error, commands.CheckFailure):
        print_e(f"No embed perms")
    elif isinstance(error, commands.MissingRequiredArgument):
        print_e(f"Missing arguments: {error}")
    else:
        print_e(f"Error: {error}")

if it thinks or knows the command is invalid, it will delete the command, skip the except block, and pass on to the following:

#

which will in-turn tell me what went wrong

#

it still removes the message

slim ibex
#

mhmm whats up

analog barn
#

okay, but it would work the same since say_delete_msg is true

#

i did fix it tho :)

#

no...

#

i mean

#

.

#

i did your suggested change

#

sorry for the miscommunication- haha

#

thank yall sm for going thru my code for me

analog barn
#

no,

#

@dasm.listen("on_message")
async def on_message(message):
    msg = message.content
    if say_delete_msg == True:
        if any(word for word in msg.lower().split() if word in wordlist):
            if not message.author.bot:
                await message.delete()
                print(f"DELETED: ('{msg}') from ('{message.author}') at {datetime.now()}")
                await message.author.send(f"Hey! We just deleted your message. `{msg}` at `{datetime.now()}`\n\nThis is because the content you've sent matched with our `Profanity Wordlist`\n\nBelieve this was a fault? type `.pardonme (your sentence)` so that we can check out what went wrong.")
                
            else:
                print(colored(f"I was about to delete my own message... but I saved myself :) {datetime.now()}", "red"))
    else:
        if any(word for word in msg.lower().split() if word in wordlist):
           if not message.author.bot:
                await message.delete()
                await message.author.send(f"Hey! We just deleted your message. `{msg}` at `{datetime.now()}`\n\nThis is because the content you've sent matched with our `Profanity Wordlist`\n\nBelieve this was a fault? type `.pardonme (your sentence)` so that we can check out what went wrong.")

#

^

#

If I decide to turn off the say_delete_msg events in the console, the feature is there for that

#

idk, I like having that feature

#

to toggle on and off debug when I need too

#

ah, for the bottom suggestion, I want to be able to do all my stuff and then check if they're a bot before I send it

slim ibex
#

await message.delete() is in every situation

analog barn
#

again, I just like having the feature haha

analog barn
slim ibex
#

is the issue that the BOT's message is being deleted

analog barn
#

yes

slim ibex
#

ahh ok

analog barn
#

but there is no reason for it to...

slim ibex
#

yeah

#

because you specifically say for it not to delete the bots msg

analog barn
#

yep, it does a prefix check and makes sure it's not a bot-

#

ik ik

#

but honestly, between you and I, so many people criticize my code style because it's not 'perfect' or 'excessive/unnessesary' to the point where I'm better off going the code style I use unless/until it affects performance or readability

#

maybe I should move the bot check above everything

slim ibex
#

idk maybe try @dasm.event()

analog barn
#

you can say that again LMAO

slim ibex
#

it shouldn't make a difference though

slim ibex
#

that is what Monkee suggested before i believe

analog barn
#

yeah

#

sorrryyyy monkeee

#

hold on while i apply the change

#

?

slim ibex
#

oh ok ye

analog barn
#

binds?

slim ibex
#

?

analog barn
#

I'm questioning whether this line of code:

async def on_message(message):
    if not message.author.bot:

returns a valid response...

#

It might be outdated or not exist at all

slim ibex
#

1 sec

#

so

analog barn
#

well in my case, we're checking the authors message and there is no bot attribute to message.bot

final iron
#

Yup

#

Remember, docs are your friend

analog barn
slim ibex
#

it should be similar to

@blah.listener()
async def on_message(message):
  if message.author.bot != True:
    ...
analog barn
#

AH HA!

#

SO IT DOES WORK

#

AND I GOT USEFULL INFO

#

so i sent "test"

#

and it returned as false

#

because im not a bot

#

but as soon as i say the f word, it deletes, and returns true

#

because it removed a bot message

#

so i guess its 100% for sure the bot is deleting it's own message

#

i know

#

but now its for sure

#

but the code is literally telling me it's detecting a bot message when I deliberately made it so it checked if it was a bot before it deleted the message

#
@dasm.listen("on_message")
async def on_message(message):
    print(message.author.bot)
    if not message.author.bot:
        msg = message.content
        if say_delete_msg == True:
            if any(word for word in msg.lower().split() if word in wordlist):
                await message.delete()
                print(f"DELETED: ('{msg}') from ('{message.author}') at {datetime.now()}")
                await message.author.send(f"Hey! We just deleted your message. `{msg}` at `{datetime.now()}`\n\nThis is because the content you've sent matched with our `Profanity Wordlist`\n\nBelieve this was a fault? type `.pardonme (your sentence)` so that we can check out what went wrong.")
            else:
                print(colored(f"I was about to delete my own message... but I saved myself :) {datetime.now()}", "red"))
        else:
            if any(word for word in msg.lower().split() if word in wordlist):
                await message.delete()
                await message.author.send(f"Hey! We just deleted your message. `{msg}` at `{datetime.now()}`\n\nThis is because the content you've sent matched with our `Profanity Wordlist`\n\nBelieve this was a fault? type `.pardonme (your sentence)` so that we can check out what went wrong.")
    else:
        print(colored(f"I almost just performed the cuss check on myself, silly me! :] {datetime.now()}", "red"))
#

so that's the issue then

#

or maybe not?

#

lets give it a try

frank tartan
analog barn
#

thankss

#

sure

#

yep

#

yep

heavy folio
#

!d discord.TextChannel.fetch_message

unkempt canyonBOT
#

await fetch_message(id, /)```
This function is a [*coroutine*](https://docs.python.org/3/library/asyncio-task.html#coroutine).

Retrieves a single [`Message`](https://discordpy.readthedocs.io/en/master/api.html#discord.Message "discord.Message") from the destination.
heavy folio
#

it's an async func, remember to await it

analog barn
#

i applied the change before he told me to-

#

or she

novel sky
#

One message removed from a suspended account.

analog barn
#

im sorry

#

the code brings back errors

#

or maybe i did smth

#

wait hold on

#

yep

#

i'm so very stupid

#

i haven't tested this out yet

#

but im sure it will fix my issue

#

see, I checked if the author is a bot sure, but because message.author.bot returns a Boolean value, I can just run a true/false check

#

yep

unkempt canyonBOT
#

discord.on_message_delete(message)```
Called when a message is deleted. If the message is not found in the internal message cache, then this event will not be called. Messages might not be in cache if the message is too old or the client is participating in high traffic guilds.

If this occurs increase the [`max_messages`](https://discordpy.readthedocs.io/en/master/api.html#discord.Client "discord.Client") parameter or use the [`on_raw_message_delete()`](https://discordpy.readthedocs.io/en/master/api.html#discord.on_raw_message_delete "discord.on_raw_message_delete") event instead.

This requires [`Intents.messages`](https://discordpy.readthedocs.io/en/master/api.html#discord.Intents.messages "discord.Intents.messages") to be enabled.
analog barn
#

o h

echo wasp
#

you bold text on a bot like this right? py **bolded**

#

or how you bold on a bot

analog barn
#

yes...

analog barn
echo wasp
#

ok i thought so but better to double check

analog barn
#

okay

#

oh, i can just do that without using that event-

dry kelp
#

How can i upload a sticker to the guild?

analog barn
#

okay wait

#

okay, testing this

#

I added the on_message_delete event

#

and so this is the codeee

#
@dasm.event
async def on_message_delete(message):
    print(f"""
    Message Deleted: {message.content}
    Message Time: {datetime.now()}

    Message Attributes: {message}
    """)
#

and here is what it returns

#
False

    Message Deleted: f*** // redacted cuss word so this message isnt deleted in the python server

    Message Time: 2022-01-29 23:15:50.795657

    Message Attributes: <Message id=937184306391031938 channel=<TextChannel id=937118844168863815 name='general' position=0 nsfw=False news=False category_id=937118843732635680> type=<MessageType.default: 0> author=<Member id=895798042379292803 name='ethapel' discriminator='9335' bot=False nick=None guild=<Guild id=937118843732635679 name='dasm test server' shard_id=None chunked=False member_count=4>> flags=<MessageFlags value=0>>

DELETED: ('f*** // again, I redacted it') from ('ethapel#9335') at 2022-01-29 23:15:51.044729
True
I almost just performed a cuss check on myself

    Message Deleted: Hey! We just deleted your message. `f*** // redactedddddddddd` at `2022-01-29 23:15:51.044729`

This is because the content you've sent matched with our `Profanity Wordlist`

Believe this was a fault? type `.pardonme (your sentence)` so that we can check out what went wrong.
    Message Time: 2022-01-29 23:15:51.575924

    Message Attributes: <Message id=937184310027497482 channel=<DMChannel id=937161374788898827 recipient=<User id=895798042379292803 name='ethapel' discriminator='9335' bot=False>> type=<MessageType.default: 0> author=<User id=937116270967550003 name='DASM' discriminator='2878' bot=True> flags=<MessageFlags value=0>>
vagrant brook
#

uhh yes whats wrong with that

analog barn
#

ah I should probably explain to newcomers to my problem

#

basically
i have a cuss filter
it deletes every message that has a cuss word in it

#

but my problem is that the bot deletes its own message when it dms the user what message the bot deleted

#

so now we're figuring out how not to delete the bots message

#

okay

#

i'm just going to open a help channel :)

#

If you would like to continue to help me, #help-pear please.

cinder horizon
#

how many servers shud a bot be in for verified bot badge?

maiden fable
boreal ravine
#

test_guild is a kwarg?

boreal ravine
#

no i mean

#

does commands.Bot have that kwarg?

#

yeah

maiden fable
#

Hmm

boreal ravine
#

you need the application.commands scope in your bot

maiden fable
#

Add the application.commands scope

boreal ravine
#

no

#

discord developers site

#

reinvite your bot with that scope

dry kelp
#

How do i get the emoji of a sticker?

#
    async for r in guild.audit_logs(limit=1, after=datetime.datetime.now() - datetime.timedelta(minutes = 1), action=discord.AuditLogAction.sticker_delete):

        remove_sticker = [r for r in before if r not in after]
        print(remove_sticker)

        for st2 in remove_sticker:
            before_sticker = await st2.read()
            
            if remove_sticker:
                await guild.kick(r.user, reason="Anti-Nuke: Deleting Stickers")
                await guild.create_sticker(name=st2.name, file=before_sticker, emoji=idkkkk)
#

remove_sticker = [r for r in before if r not in after] won't return it

boreal ravine
#

i dont think stickers have emojis

#

add a decorator to the slash command or check the authors permissions inside the slash ommand

slate swan
#

!d discord.ext.commands.has_permissions

unkempt canyonBOT
#

@discord.ext.commands.has_permissions(**perms)```
A [`check()`](https://discordpy.readthedocs.io/en/master/ext/commands/api.html#discord.ext.commands.check "discord.ext.commands.check") that is added that checks if the member has all of the permissions necessary.

Note that this check operates on the current channel permissions, not the guild wide permissions.

The permissions passed in must be exactly like the properties shown under [`discord.Permissions`](https://discordpy.readthedocs.io/en/master/api.html#discord.Permissions "discord.Permissions").

This check raises a special exception, [`MissingPermissions`](https://discordpy.readthedocs.io/en/master/ext/commands/api.html#discord.ext.commands.MissingPermissions "discord.ext.commands.MissingPermissions") that is inherited from [`CheckFailure`](https://discordpy.readthedocs.io/en/master/ext/commands/api.html#discord.ext.commands.CheckFailure "discord.ext.commands.CheckFailure").
slate swan
#

What exactly went wrong with this code? ```@client.command()
async def unban(ctx, *, member):
banned_users = await ctx.guild.bans()
member_name, member_discriminator = member.split('#')

  for ban_entry in banned_users:
    user = ban_entry.user

    if (user.name, user.discriminator) == (member_name, member_discriminator):
      await ctx.guild.unban(user)
      await ctx.send(f":ok_hand: Unbanned {member.mention}")
      return``` Its an unban feature for my discord bot
echo wasp
#

If I edit a cog while the bot is running do I need to restart my bot?

visual island
#

has_guild_permissions checks the member's perms in that guild, while has_permissions checks the member's permissions in the specific channel

echo wasp
slate swan
echo wasp
#

So yea restart my bot

slate swan
#

Huh

visual island
#

has_permissions is enough imo

slate swan
#

imagine

echo wasp
#

My load and unload is in my bot.py file

#

Then all my commands and such is in cogs

slate swan
echo wasp
#

How

slate swan
#

!d discord.ext.commands.Bot.add_cog

unkempt canyonBOT
#

add_cog(cog, *, override=False)```
Adds a β€œcog” to the bot.

A cog is a class that has its own event listeners and commands.

Changed in version 2.0: [`ClientException`](https://discordpy.readthedocs.io/en/master/api.html#discord.ClientException "discord.ClientException") is raised when a cog with the same name is already loaded.
echo wasp
#

I do that

slate swan
#

!d discord.ext.commands.Bot.remove_cog

unkempt canyonBOT
#

remove_cog(name)```
Removes a cog from the bot and returns it.

All registered commands and event listeners that the cog has registered will be removed as well.

If no cog is found then this method has no effect.
echo wasp
#

I don't remove cogs

slate swan
#

Remove and add again

echo wasp
#

Hold on a minute

slate swan
#

holds

echo wasp
#
# bot.py
#Import list
import os
import discord
import time
import datetime
import asyncio
from discord.ext import commands
from dotenv import load_dotenv
#________________________________________________
#File Configs
load_dotenv()
TOKEN = os.getenv('DISCORD_TOKEN')
GUILD = os.getenv('DISCORD_GUILD')
intents = discord.Intents.default()
intents.members = True
client = commands.Bot(command_prefix='&', intents=intents, owner_id=786788350160797706, Help_command=None, case_insensitive=True)
bot = client
bot.remove_command('help')
#__________________________________________


@bot.command()
async def load(ctx, exstension):
  client.load_extension(f'cogs.{exstension}')


@bot.command()
async def unload(ctx, exstension):
  client.unload_extension(f'cogs.{exstension}')


client.load_extension("cogs.fun")    
client.load_extension("cogs.invite")
client.load_extension("cogs.Events")
client.load_extension("cogs.commands")


client.run(TOKEN)``` is my bot.py file
slate swan
#

And?

#

Whats the issue

echo wasp
#

my cogs go like```py
import os
import discord
import time
import datetime
import asyncio
from discord.ext import commands

class Invite(commands.Cog):

def __init__(self,client):
    self.client = client

def setup(client):
client.add_cog(Invite(client))```

slate swan
#

And?

echo wasp
#

so do i need to restart my bot if i edit anything in my cog?

slate swan
#

!d discord.ext.commands.Bot.unload_extension

unkempt canyonBOT
#

unload_extension(name, *, package=None)```
Unloads an extension.

When the extension is unloaded, all commands, listeners, and cogs are removed from the bot and the module is un-imported.

The extension can provide an optional global function, `teardown`, to do miscellaneous clean-up if necessary. This function takes a single parameter, the `bot`, similar to `setup` from [`load_extension()`](https://discordpy.readthedocs.io/en/master/ext/commands/api.html#discord.ext.commands.Bot.load_extension "discord.ext.commands.Bot.load_extension").
slate swan
echo wasp
#

Ok

faint monolith
#

I finally changed my bot language to java from python... so sad...

maiden fable
#

Why tho

echo wasp
#

How would I put a thumbs up into my bots messages? πŸ‘

#

That one to be on point

faint monolith
#

I tried a lot to put slash commands on my bot but i just stopped trying...

slate swan
spring flax
faint monolith
#

And I cannot handle normal messages and commands tohether

spring flax
#

What lib did you use?

faint monolith
visual island
#

list() it

boreal ravine
#

cast*

spring flax
faint monolith
visual island
faint monolith
slate swan
faint monolith
visual island
#

ohh, you can use channel.history()

spring flax
visual island
#

!d discord.abc.Messageable.history

unkempt canyonBOT
#

async for ... in history(*, limit=100, before=None, after=None, around=None, oldest_first=None)```
Returns an [`AsyncIterator`](https://discordpy.readthedocs.io/en/master/api.html#discord.AsyncIterator "discord.AsyncIterator") that enables receiving the destination’s message history.

You must have [`read_message_history`](https://discordpy.readthedocs.io/en/master/api.html#discord.Permissions.read_message_history "discord.Permissions.read_message_history") permissions to use this.

Examples

Usage...
faint monolith
#

Eh man WHAT?

spring flax
#

What?

faint monolith
#

Why?

slate swan
spring flax
#

Why what?

faint monolith
#

Why discontinued?

echo wasp
#

How do I bold the user name and not ping them and show tags

slate swan
spring flax
#

The core maintenaner stopped development

slate swan
faint monolith
#

So

visual island
faint monolith
#

Gimme the instructions for disnake

spring flax
#

Unfortunate that you weren't aware

slate swan
unkempt canyonBOT
faint monolith
#

I will give a try (another try)

visual island
#

messageble can be any channel that can be sent, TextChannel, DMChannel , etc

spring flax
faint monolith
#

But I also develop my second bot in Java...

visual island
#

no sorry

visual island
faint monolith
maiden fable
echo wasp
spring flax
#

Ane ask here if you are facing issues

echo wasp
#

Like that

visual island
slate swan
maiden fable
visual island
maiden fable
echo wasp
visual island
slate swan
visual island
#

it is

echo wasp
maiden fable
slate swan
unkempt canyonBOT
#

property discriminator```
Equivalent to [`User.discriminator`](https://discordpy.readthedocs.io/en/master/api.html#discord.User.discriminator "discord.User.discriminator")
spring flax
#

Hunter it's such a big deal huh

maiden fable
spring flax
#

Bruh

maiden fable
#

Use isinstance

echo wasp
maiden fable
#

Lmao

slate swan
spring flax
#

!d isinstance

unkempt canyonBOT
#

isinstance(object, classinfo)```
Return `True` if the *object* argument is an instance of the *classinfo* argument, or of a (direct, indirect, or [virtual](https://docs.python.org/3/glossary.html#term-abstract-base-class)) subclass thereof. If *object* is not an object of the given type, the function always returns `False`. If *classinfo* is a tuple of type objects (or recursively, other such tuples) or a [Union Type](https://docs.python.org/3/library/stdtypes.html#types-union) of multiple types, return `True` if *object* is an instance of any of the types. If *classinfo* is not a type or tuple of types and such tuples, a [`TypeError`](https://docs.python.org/3/library/exceptions.html#TypeError "TypeError") exception is raised.

Changed in version 3.10: *classinfo* can be a [Union Type](https://docs.python.org/3/library/stdtypes.html#types-union).
maiden fable
#

Just do {member}

It will automatically give the discrimintor and name

visual island
#

TextChannel, Thread, DMChannel, GroupChannel

spring flax
#

Just give the full code

echo wasp
maiden fable
#

isinstance(channel, disnake.TextChannel)

echo wasp
maiden fable
#

inter.channel

final iron
#

Hello chat

unkempt canyonBOT
#

Pasting large amounts of code

If your code is too long to fit in a codeblock in discord, you can paste your code here:
https://paste.pythondiscord.com/

After pasting your code, save it by clicking the floppy disk icon in the top right, or by typing ctrl + S. After doing that, the URL should change. Copy the URL and post it here so others can see it.

visual island
#

rather than using multiple try-except for HTTPException, use on_command_error

#

it catches every exception that's raised in a command

#

but you would check manually if the error raised is the expected exception

#

yes

#

!d discord.ext.commands.Command.error or this to make the error handler to handle just a command

unkempt canyonBOT
#

@error```
A decorator that registers a coroutine as a local error handler.

A local error handler is an [`on_command_error()`](https://discordpy.readthedocs.io/en/master/ext/commands/api.html#discord.discord.ext.commands.on_command_error "discord.discord.ext.commands.on_command_error") event limited to a single command. However, the [`on_command_error()`](https://discordpy.readthedocs.io/en/master/ext/commands/api.html#discord.discord.ext.commands.on_command_error "discord.discord.ext.commands.on_command_error") is still invoked afterwards as the catch-all.
visual island
#

sure

final iron
#

Then your computer explodes

visual island
#

on_error event will catch that

#

if you have 1

#

cause you're not directly overriding it from your Bot class, you're overriding it by creating a new listener, thus the linter wouldn't know what method you're overriding

final iron
#

Nothing

#

I misunderstood