简体   繁体   English

discord.py on_message 定义冲突?

[英]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.您可以尝试使用cog或合并函数的代码。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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