最近,我的bot正在增长,我花时间重写代码,使其能够与Discord Py的cogs系统一起工作
我已经正确地修改了所有代码,但是我已经停止工作的所有on_message
事件都没有抛出任何类型的错误消息
模块加载正确,没有语法错误,因此我无法理解可能发生的情况
我的一些代码:
import discord
import random
import datetime
from discord.ext import commands
class eastereggs(commands.Cog):
def __init__(self, bot):
self.bot = bot
self._last_member = None
@commands.Cog.listener()
async def on_message(self,message):
Cheers= ["Hi", "hi", "Hello", "hello"]
if message.content in Cheers:
await message.channel.send('Hello again')
await self.bot.process_commands(message)
def setup(bot):
bot.add_cog(eastereggs(bot))
但是,它不会对数组中的任何问候语作出反应
我编辑:我有多个带数组的on_消息事件
但似乎只有一个可行
问题在于不能有两个同名函数。如果你这样做,它只会调用最后一个。将加载该文件,但不会给出任何错误。由于所有事件都是
on_message
事件,因此只有最后一个事件可以工作。但是,你可以告诉听众“听”什么您可以使用
@Cog.listener("on_message")
(或以相同方式使用其他事件),然后以不同的名称调用函数您需要取消登录
process_commands
在你的每一次活动中, 另外,如果您想让代码更干净、更健壮,还有
bot.dispatch
来创建自定义事件,遗憾的是,没有关于它的文档相关问题 更多 >
编程相关推荐