Reputation: 1491
I am using discord.py to make my discord bot and when somebody types a message I want to check if the user is lets say foo#3645 and then do something if it is not then do something else
if(messageAuthor == "foo#3645):
# do something
else:
# do something else
I tried this:
if(ctx.message.author == "foo#3465"):
# do something
but that is not working for some reason...
If you need more info please comment.
Upvotes: 1
Views: 30754
Reputation: 1257
if you want a reliable check, check for user ids:
if author.id == 170733454822341405:
#do something
Upvotes: 7
Reputation: 303
Checking for a user ID is your best bet. According to the docs, User.id
is an integer, not a string, so the accepted answer may not work. message.author
is of type User
.
This is what worked for me:
if message.author.id = 170733454822341405:
#do something
To get someone's user ID manually, enable developer mode in discord (user settings -> appearance -> advanced), then just right click on a user anywhere and click copy ID.
Upvotes: 1
Reputation: 60984
The str
representation of a User
(including Member
s) will be their username (not their server-specific nickname), and the discriminator (used to tell people with the same username apart).
if str(ctx.message.author) == "foo#3465":
...
That said, you should be checking against id
s, as it is possible for a person to change their Discord username. id
s are strings in the async branch of discord.py and integers in discord.py-rewrite
Upvotes: 5