2
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)

4 Answers 4

1
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.

Sign up to request clarification or add additional context in comments.

Comments

0

You're using await client.send_message() instead of await bot.send_message().

Comments

0

maybe instead of await client.send_message(message.channel, 'I noticed you @{}!'.format(author)), try await message.send('I noticed you @{}!'.format(author))

Comments

0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.