#discord-bots
1 messages Β· Page 788 of 1
What lib are u using
how do I pass in the request headers? is it a dict or...?
its a dict
Itβ s a dict yes
headers = {"auth" : "token"}
note this is an example your api can have different headers
I dont even know rn
ooo, ok, thank you
U dont know what library ur using?
yw
how would you not know what lib youre using
quickest way is to check imports lmao
Well I learned Python my self without youtube tutorials or so only like asking questions and asking on stack overflow and its working fine but i dont know, where can i see that?
At this point, I think thats a skill that takes time and dedication to acquire
Imports
Also you should consider reading docs etc. on pythob
Python
prob
Making a discord bot is going to be hell if you don't even know what library you're using
You should learn python first
you probably know nothing
No cogs and replit?
Please take a look at python basics first
U need to understand what we say when we help you
^^
as those tutorials are old and teach old stuff which is probably deprecated or old to use
^^
Lucas π
fcc
Lmfao
CheckFailure
im_a_failure = true
how to make the discord bot reply to message?
.reply
ctx.reply instead of ctx.send
Not always ctx )
its a method
I got this error the code is also attached.
But at your level I feel like u would use ctx at the start
await message.channel.send(reply)
!d discord.abc.Messageable.reply
no replace .send with .reply
Fuc
Ticket system?
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)
What is it
without pinging the poeple?
Reaction roles.
I would recommend using buttons tho
Its so much easier ngl
member is none
I think there is a payload.member attribute
Nvm
Itβ s reaction remove
Thank you.
^^
What do I do?
Only add
Like what event?
What event are you looking for?
There are all events in the docs
How to get when the user replies to the bot but without using the @ bot_name?
Under event reference
!d discord.on_raw_reaction_remove
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.
Whoever was trying to find it
Thanks
Me.
is that what the <@!{}> vs <@{}> means>
Eh I didn't even know these existed. Docs probably need update
Are you using a fork or discord.py?
U might find it in discord.py github?
Says payload has member attribute
what is the difference between the <@!{}> vs <@{}> ?
It returns None. Check the discord docs
It straight up doesn't return a user id
for if message.content.startswith('<@!{}>'.format(client.user.id)) or message.content.startswith('<@{}>'.format(client.user.id)):
One is pc mention, other one mobile
Its very weird, I used it 5 months ago
outdated
how to return a message when the user replies to the bot directly but does not mention the bot
Yes ik, I had problems with that π
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.
Good to hear u found it
nickname
Dpy 2.0 indeed
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>
!d discord.Message
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.
if you want a bookmark reply to the msg and do the .bm if you want the bot to dm you it (its useful)
Does anyone honestly use this typehint?
yes i do
I never did and didn't get any issues with it
type hints dont affect run time
!d discord.Message.content
The actual contents of the message.
!d discord.Message.reference
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.
so if the user replies to the bot is that captured by the 'mention capturer'?
But they affect coding time
#bot-commands for personal uses
?
They affect typing time*
lol
That's what I meant
i do
@bot.listen()
async def on_message(message: Message) -> None:
lol
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?
Okay how do I fix it?
havent worked with payload
I dont think so, also you can do message.mentions to get a list of all mentions
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?
on_message event
No
just check the content
so wait
!d commands.on_message
No documentation found for the requested symbol.
@final iron
!d discord.on_message
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.
Ty
Client has it aswell
And also try to use @bot.listen("on_message")
And not the event. The event can block your code
listen()
@bot.event()
async def on_message(ctx):
if ctx in wordlist
await #do smth
Goot to know
right?
Mb, getting confused with cogs
ik bad python formatting
no
message.content
@bot.event doesn't need brackets either
if message.content
^^
or ctx.content since the message obj is context cuz of arg naming
i make that error so much π
!d discord.ext.commands.Context
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.
@bot.event()
async def on_message():
if message.content in wordlist:
await #do smth
Don't mind indents, mobile
correct?
No
no add message to params
on_message(message)
Please use @bot.listen("on_message")
Its the same as ur event, just doesn't block ur code
no need for the arg given
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)
Mhm
@bot.listen("on_message")
async def on_message(message):
if message.content in wordlist:
await #do smth
right?
doesnt block your code its just events if its in message it overwrites itself
u would need bot.process_commands if I'm right
okay how about i just keep it
Not if he uses listen?...
yes
only if you add the event in the listen
Which is what he did
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)
he did both
Author for any role?..
Indeed
just check the roles of the author
@commands.slash_command*
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
Bro pls
!d disnake.ext.commands.Bot.test_guilds
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.
Then do @bot.slash_command
How
you did exc
U need to set this @slate swan
or then youll have to wait 1hour so the slash commands registers globally
did you see my message?
example?
Yeah I think I did, u would need id tho
why are yall being so aggressive smh?
and need to give them a name
but when I do
for role in member.roles:
if role.name in info.roleList:
it works with names
well if u got that working, u can figure it out urself right?
ctx.author.roles?
Lmao if you click the link and read, I wont need to explain it
well it says no even if they have one of the roles, thats why im here ;/
Ik u know what they are
Then it doesn't work
Send ur script please.
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
if he does have an arg then yes if not no
in the command i used
for role in member.roles:
if role.name in info.roleList:
in, yes
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
True
Depends on the argument, mb
Wdym u cant use it
so any other ideas?
no
That's literally what u said?
Try self.slash_command π€·πΌββοΈ
Cus ur inside class
self is a parameter that accesses the objs in a class
π
^^^^^^^^^^^
so do you have any other ideas?
Please stop helping if you don't know the answer
that is so
Who even thinks of self in their command type
i do know?i just never have done that?
bro what?
esoteric people
whats your error/issue?
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
didnt you thought type hints had affect on run time
ποΈ ποΈ
I said coding time π€¦ββοΈ
And bc u didn't even understand that, I had to say typing time
Ik python was made in c but whats the difference between cpython and python
you said you didnt have problems with type hints ofc you wont get any error
it wont raise an error like: "not true typehint"
Take a look from here, never even said it affected run time
i have?
Then why u say that I said it affects run time? 
because you did
Where?
scroll
Reply to my message right now
scroll
No, I don't see it, you go reply to it for me
well this is not possible since you'd need to access self to make the slash command
you said you didnt have errors with typehinting ofc you wont get a error
bruh
"I never did and didn't get any issues with it" ofc you wont have an issue it doesnt affect run time and its a positional argument

have there already been migration guide for when discord.py will shut down? 
make it outside the class ```py
bot = Application()
@bot.slash_command()
async def my_slash():
...
try again though, bc right now you're just getting frustrated
ok, read your message. Did I say it affected runtime? I said if I got no issues with it, why would I use It
I wasn't even helping him but he keeps correcting me wrong.
if typehints did you would get an error and the code would stop affecting run time
Imma head to help channels rq my brain can't take this
Well discord.py's development has ceased already. For migration you can just pip install disnake and just find and replace each discord to disnake
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?)
!d discord.Member.roles
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.
It returns a list of role objects
you're using disnake right?
iterate through that list
lmao he left he couldnt prove himself right 
hmmm ok
A simple script to add application command support to discord.py v2.0 - GitHub - XuaTheGrate/slash_util: A simple script to add application command support to discord.py v2.0
ok that's just antagonizing the situation. don't do that
This is what most people use.
I couldn't take the way u were stupid and couldn't prove I said something?
!silence
β silenced current channel for 10 minute(s).
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
β unsilenced current channel.
β
Why are you recommending this to him when hes already using disnake?
Well here monkee
Aren't you using disnake? Disnake already has slash command support
it's usable with d.py master
I didn't know he was using disnake?...
disnake has slash command support.
Let me take a look for disnake
i think Danny recommends slash_util idk
does he?
@slate swan docs: https://docs.disnake.dev/en/latest/ext/commands/slash_commands.html
Β―\_(γ)_/Β―
^^^ Read this thoroughly. Don't skip any of it
Its a pretty good explanation. Wish discord.py didn't get discontinued
I'm pretty sure everyone didn't want dpy to get discontinued
Is there a big difference between discord and disnake? If not, I might switch.
and it says "slash command support for dpy 2.0"
no not really
just names and the new features
If you really care then you can just import disnake as discord
And you're fine
icon = str(ctx.guild.icon_url)
await ctx.send(icon)``` this sends a blank picture with
I see
So the only actual advantage that would give me are / commands?
Also getch
get channel
Probably some other stuff I'm missing
do you have guild intents
Alright, don't know if it's worth it tho
no getch is only for disnake
yes, i figured it out never mind
getch tries to get it from cache and if it fails it fetches it
Ah get fetch
yeah you said get? i thought you corrected him
Don't think I am
yes
Yup
It isn't indeed
What does getching support
or switch to better lib hikari
channels and guilds irrc
you cant getch users or messages users idk why its not implemented
Why don't they expand what you can getch?
you can't get a msg and for user idk they just haven't implemented it
is hikari a fork?
no another discord api wrapper
I've seen hikari, hikari is more complex than d.py
!pypi hikari
im pretty sure you use disnake
yep (to lazy to change)
does it what features does it have better than dpy
been told the comunity are a bit toxic not sure if its true
does it what?
i need a reasonποΈ ποΈ
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
If the message content intent is going to be hard to get doesn't that mean custom commands are dead?
correct
you can only get it if you hsve a good reason for it
I guess something like /tag <tag> will work but its not really a custom command
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
Fuck Discord's handling of developers
wdym
lmfao
What
nvm lol
Can I have Name arg in the parentheses of @ commands.Cog.listener()?
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?
probably
!d discord.ext.commands.Cog.listener
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").
yep
It says βTypeError listener() got an unexpected keyword arg βNameββ
...anyone-?
Do smth like if the message is not in the cuss words array then return
just lower the content and check it in a list of lower case cuss words
show
@commands.Cog.listener(Name = 'on_message', description = 'react with message')
async def on_message(self, message):
if message.author == self.bot.user:
return
remove name=
or remove the whole arg
because the function is named on msg
I changed the name of Name
The actual Name arg is not on_message
ic
no need for it tbh
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
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-
only message can be used
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
also, I want it to delete the message if it finds there is a bad word in the phrase too...
await message.delete()
yes, I am using that
but after testing, I can bypass my filter by putting my cuss word into a sentence.
- events dont have context
- on message event only takes 1 argument
- use await message.channel.send
- no need to process the comma d since youre using listen
- message.content is a string why make it a string
you are checking ```py
if "a long sentence you send to discord" in ["list" ,"of","words"]:
yes thats why
it's because i'm formatting message.content to lowercase
yes all the list should be lower case
I need a way to check if any of the words that are in my wordlist are in the user's message
so no matter how someone makes the word so uppercase it will lower it and check in a lowercase words list
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.
!e print(" okimii is cool" in ["okimii"])
@slate swan :white_check_mark: Your eval job has completed with return code 0.
False
i'm doing it because people can bypass by making the cuss word uppercase
use any and iterate inside the list of words
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
if any([m for m in msg.split() if m in cuswords]):
...
You can still do that with the following:
message.content.lower()
it wouldn't let me
There are much more pythonic ways of doing the first, but that should work lol.
Can we see your current code?
what do you mean? what else do you need to see?
!e ```py
sentence = "okimii is cool"
listofwordss = ["okimii"]
print(any(word for word in sentence.lower().split() if word in listofwordss))
@slate swan :white_check_mark: Your eval job has completed with return code 0.
True
and here's how it works.
This works too.
Why are you defining a list of role objects like that?
use get_role to get the role objects
I forgot about the good ol "any" built-in π
cuz i originally had a list of role names, but i was told i need role objects
but i cant even run my code anymore
cuz i get a syntac error
Why not just store the id and get/fetch the roles?
uhhhhhh
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
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)```
did you see my message?
uid not accesed?
?
@green raptor btw you can just do py for code blocks no need for python (its faster)
JSON is not and should not be used as a database
why
its not for storing data and its used for formatting data
what else do u recommend
if you make a request to an api MOST apis respond with json formatted data
sqlite3
but just the async bridge aiosqlite
ok lemme look up tutorials
Wait, why were you passing user.id to get_bank_data if it has no current usage?
idk what u mean
but i think i should use sqlite
True. True.
On the call: users = python await get_bank_data(user.id) you have user.id as an argument.
If you're not going to use it in the get_bank_data function, yes.
And remove the await
is not defined
and remove the uid
You shouldn't make get_bank_data a coroutine if it isn't even doing any asynchronous operations
^
with
async def -> def
Your functions are still coroutines
Oh wait you did change it
Did you save it??
yes pretty sure lemme re run
Ok I tried it failed how do I mention q member that joined?
doesnt work
It tends to be the simplest mistakes.
no ()
^
just member.mention
and it should be in an f-string
Can you add a print into your setup function where the OnReady cog is
seems like swas' code...
So your cog_loader code inside of your main file didn't call load_extension on the on ready file
who is swas
a discord bot developer
Make sure you are looking at the correct path, files etc
kk
yes its a property
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
i dont think thats the error...
shouldnt it be @commands.Cog.listener
as its in a cog
He imported Cog from commands, literally the same thing you sent
thats not needed...
Yea, not-needed but not the error
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
Guys does anyone know how to place strings in sqlite data
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
it should be the same as how you would regularly import something in sqlite
and yes ^
π
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
O ok-
uhhh ill stop you before you have to fix other errors later on...
iirc there is something to store something a certain type
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?
wow thanks a lot
!sql-fstring
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
You def want to avoid the f-string inside of your first execute call
Switch it for parameters
isnt he fine
hes using place holders which sql doesnt execute the SQL statements
or am i wrong?
I'm talking about the f-string, the {user.id}
That opens a lot of vulnerabilities
ah sorry didnt saw that
i think you can do
"hello" Text
im not sure
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...
Are your dms off?
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
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.
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
Why do you have your Bot constructor variable called dasm
I would ditch the habit
It's bad practice
Whats better? SQL or MongoDB
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.
mongodb
the whole code would exceed the message character limit on discord
But it makes it more confusing for others and makes it harder to maintain code
# SETTINGS
bot_debug = False
say_delete_msg = True
If you're every going to work with a team, building these bad practices are going to bite you in the ass later on
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.
SQL is the query language. it isn't a database
got it
Could I use JSON as like a config?
Not recommended
I need to check out yaml
yaml is pog
don't mind the imports, I am importing things I am sure I will need in the future.
I hate sending my whole bot code because although unlikely, It is so easy for people to just steal my code... but okay.
https://paste.pythondiscord.com/tubozedomo.py
Then why was Monkee talking about using it to store config data?
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
it is used to do that also
Ah, so its just a more human readable json?
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
Don't use a bare exception block
i had one
Or else you'll be getting a visit from me...
πΏ
i need friends anyway
i had one, i only recently removed it for a sec
Using a bare exception block is a no no in the eyes of pep8
ik
but atleast its something
you can print the exception
^
what error would the command raise if there was one
exception*
all it does is return the error if it can't process the stuff in the try block
if there is an error
hold on
You want to do something like this: except asyncio.TimeoutError
see it doesnt give errors
Notice how I'm catching the specific error
but removing the on command thing
And not using a bare exception block
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
@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
mhmm whats up
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
this code?
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
await message.delete() is in every situation
again, I just like having the feature haha
for now yes..
is the issue that the BOT's message is being deleted
yes
ahh ok
but there is no reason for it to...
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
idk maybe try @dasm.event()
you can say that again LMAO
it shouldn't make a difference though
that is what Monkee suggested before i believe
binds?
?
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
well in my case, we're checking the authors message and there is no bot attribute to message.bot
i'm going to check if it even works hold on
it should be similar to
@blah.listener()
async def on_message(message):
if message.author.bot != True:
...
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
Thatβs cool
!d discord.TextChannel.fetch_message
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.
it's an async func, remember to await it
One message removed from a suspended account.
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
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.
o h
yes...
await ctx.send("**this is my bolded message**")
ok i thought so but better to double check
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>>
uhh yes whats wrong with that
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.
how many servers shud a bot be in for verified bot badge?
At least 75 servers, then bot goes in for verification and BTW the badge is discontinued
test_guild is a kwarg?
aighty...
Hmm
you need the application.commands scope in your bot
Add the application.commands scope
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
i dont think stickers have emojis
add a decorator to the slash command or check the authors permissions inside the slash ommand
!d discord.ext.commands.has_permissions
@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").
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
If I edit a cog while the bot is running do I need to restart my bot?
has_guild_permissions checks the member's perms in that guild, while has_permissions checks the member's permissions in the specific channel
Reload the cog
How do I reload the cog?
Unload and load again
So yea restart my bot
Huh
has_permissions is enough imo
imagine
Then make a command so that the cog is unloaded and loaded again
How
!d discord.ext.commands.Bot.add_cog
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.
I do that
!d discord.ext.commands.Bot.remove_cog
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.
I don't remove cogs
Hold on a minute
holds
# 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
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))```
And?
so do i need to restart my bot if i edit anything in my cog?
!d discord.ext.commands.Bot.unload_extension
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").
Thats what i said, dude, try reloading the cogs
Ok
I finally changed my bot language to java from python... so sad...
Why tho
Why?
I tried a lot to put slash commands on my bot but i just stopped trying...
Write +1 between colons
You should have used disnake
And I cannot handle normal messages and commands tohether
What lib did you use?
S.A.D.
I never knew that hm
discord
discord.py
discord.ext
list() it
cast*
That's the issue lol
When you fail many times, you juat stop trying...
yeah that
So what and how do i use that
I know, i follow that
After 100 times even?
ohh, you can use channel.history()
Discord.py development has stopped, so it doesn't support the full Discord api features.
You could've used disnake
!d discord.abc.Messageable.history
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...
Eh man WHAT?
What?
Why?
After 7, i'm done
Why what?
Why discontinued?
How do I bold the user name and not ping them and show tags
Cuz why not
The core maintenaner stopped development
Give some context of your command
works on both disnake and discord.py
Gimme the instructions for disnake
Unfortunate that you weren't aware
!pypi disnake
I will give a try (another try)
messageble can be any channel that can be sent, TextChannel, DMChannel , etc
There are examples on the github for slash commands
But I also develop my second bot in Java...
no sorry
VoiceChannel π
im drunk
I saw a lot of them... but i will see them again
CategoryChannel π
await channel.send(f"**{userwithtags}** has left the server")```
Ane ask here if you are facing issues
Like that
π
How are you getting the user?
Threads? π
included in etc
Bruh, u serious?
I was using {member.name} but I want tags
it isnt a Messageable?
Use the discriminator property
it is
Example
It is... I meant to say, there are hardly 3-4 messageable classes, still you using etc, just why
!d discord.Member.discriminator dude
property discriminator```
Equivalent to [`User.discriminator`](https://discordpy.readthedocs.io/en/master/api.html#discord.User.discriminator "discord.User.discriminator")
Hunter it's such a big deal huh
yes Nah, just telling
Bruh
Use isinstance
Ok so {member.name.discriminator}?
Lmao
Dude
4
!d isinstance
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).
Just do {member}
It will automatically give the discrimintor and name
TextChannel, Thread, DMChannel, GroupChannel
Just give the full code
Or {member.discriminator}
isinstance(channel, disnake.TextChannel)
@echo wasp
Oh good to know thank you
inter.channel
Hello chat
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.
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
@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.
sure
Then your computer explodes


