简体   繁体   中英

discord.py on_message definitions conflicting?

This is the code:

async def on_message(message):
    if client.user.mentioned_in(message):
        await message.channel.send("Hey!")

@client.event
async def on_message(message):
    if message.author == client.user:
        return

    if "$example" in message.content:
        if message.author.id == int(discord id here):
            await message.channel.send("Hi Name")
        if message.author.id == int(discord id here):
            await message.channel.send("Hi Name2")

So, my issue is if I have the second piece of code in, my first piece of code doesn't work. No error messages, nothing it just doesn't seem to exist. I'm assuming it would also be the same vice versa. My question is: I'd like to know what's causing this and how I should go about fixing it. Is my code incorrect? Am I missing something? Or should I be defining one of them as something else? I'm stuck. Thanks in advance.

There can not exist two functions with the same name in the same file. You can try using a cog or merging the code of your functions.

i was having the same problem but i managed to solve it. At the end of the second class put

`await bot.process_commands(message)`

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM