How do I fix “Unresolved reference ‘message’” in discord.py?

I’m currently coding a bot in PyCharm. I’m trying to make it so that the bot responds to a user when that user mentions them. Here is the code.

@client.event
async def on_message(msg):
    if str(client.user.id) in msg:
        em = discord.Embed(title="404Bot Help", description="Use $help <command> for extended information on that command.")

        em.add_field(name="Information", value="help, server, about")
        em.add_field(name="Moderation", value="clear")
        em.add_field(name="Chat", value="send, hello, speak")
        em.add_field(name="Games & Fun", value="coinflip, 8ball")
        em.add_field(name="Miscellaneous", value="test")

        await client.send_message(embed=em)

But for some reason, it shows me this error.

enter image description here

Disclaimer:

I am quite new to discord.py, so please respect that fact. Good day.

Answer

You need to use msg.channel.send. Also, in your if-statement, use msg.content instead of just msg.

@client.event
async def on_message(msg):
    if str(client.user.id) in msg.content:
        em = discord.Embed(title="404Bot Help", description="Use $help <command> for extended information on that command.")

        em.add_field(name="Information", value="help, server, about")
        em.add_field(name="Moderation", value="clear")
        em.add_field(name="Chat", value="send, hello, speak")
        em.add_field(name="Games & Fun", value="coinflip, 8ball")
        em.add_field(name="Miscellaneous", value="test")

        await msg.channel.send(embed=em)

Leave a Reply

Your email address will not be published. Required fields are marked *