Reputation: 21
client = discord.Client()
noticeme = 'notice me senpai'
@bot.event
async def on_message(message):
author = message.author
authorid = message.author.id
print ("@{} user sent a message. (id: {})".format(author, authorid))
if message.content == noticeme:
print ('I noticed you @{}!'.format(authorid))
await client.send_message(message.channel, 'I noticed you @{}!'.format(authorid))
I'm trying to make a command that responds with "I noticed you @username!" when you say "notice me senpai" but it doesn't work. (the print DOES work)
Upvotes: 2
Views: 11187
Reputation:
I noticed you are using @bot.event
instead of @client.event
because you have named your bot variable "client" and not "bot" in the first line of shared code it says:
client = discord.Client()
Then in the on_message
event:
@client.event
async def on_message(message):
print("{} sent a message.".format(message.author.mention))
if message.content == "notice me senpai":
print ('I noticed you {}!'.format(message.author.mention))
await message.channel.send("I have noticed you {}.".format(message.author.mention))
As you noticed, I didn't use the "author" variable here because it is not that useful. you can just do: message.author.mention
instead of assigning a variable a first and then mentioning it.
Tip: You can replace 6th line with:
if message.content.lower == "notice me senpai":
So that even if user type it in any other way say "nOtIce me senpai" with capital letters in it. It will still send the message.
Upvotes: 0
Reputation: 1
maybe instead of await client.send_message(message.channel, 'I noticed you @{}!'.format(author))
, try await message.send('I noticed you @{}!'.format(author))
Upvotes: 0
Reputation: 21
client = discord.Client()
noticeme = 'notice me senpai'
@client.event
async def on_message(message):
author = message.author
authorid = message.author.id
print ("@{} user sent a message. (id: {})".format(author, authorid))
if message.content == noticeme:
print ('I noticed you @{}!'.format(authorid))
await client.send_message(message.channel, 'I noticed you @{}!'.format(author))
This should be your code.
You used @bot.event
which should be replaced by @client.event
.
I tested your code and if you want to use an @
mention you need to use the author
variable instead of the authorid
one.
Hope this helps.
Upvotes: 1
Reputation: 255
You're using await client.send_message()
instead of await bot.send_message()
.
Upvotes: 0