【发布时间】:2022-01-15 01:13:59
【问题描述】:
这是代码:
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")
所以,我的问题是,如果我有第二段代码,我的第一段代码就不起作用。没有错误消息,它似乎不存在。我假设反之亦然。 我的问题是:我想知道是什么原因造成的,以及我应该如何解决它。我的代码不正确吗?我错过了什么吗?还是我应该将其中之一定义为其他东西?我被困住了。提前致谢。
【问题讨论】:
-
on_message一次只能引用其中一个函数。我本来预计会出现某种运行时错误,但是自从我写了一些 python 以来已经有一段时间了。查看其他 SO 帖子:Methods with the same name in one class in Python -
我是他们没有被同时使用,我相信 discord py 的重点是单独编程每个机器人命令,这意味着程序不会同步运行。这就是为什么我对这个问题感到困惑,因为每个定义都不应该知道另一个存在。
-
Python 不允许定义两个或多个同名函数
标签: python discord discord.py