【发布时间】:2021-09-14 08:03:54
【问题描述】:
我正在开发一个用于随机使用的 discord.py 机器人,我第一次尝试在 Cog 中制作我的 on_message 事件,我查看了不同的示例并尝试了这个:
import discord
from discord.ext import commands
class AntiSpam(commands.Cog):
def __init__(self, client):
self.client = client
@commands.Cog.listener()
async def on_message(self, message):
if len(message.content) > 350: # Anti-Spam for message lenght
await message.delete()
await message.channel.send(f'{message.author.mention}, <a:cat_no:843799913958866955> You are **not** allowed to send unnecessarily long and annoying messages in this server!', delete_after=5)
await self.client.process_commands(message)
def setup(client):
client.add_cog(AntiSpam(client))
现在,一切正常,直到我在添加该事件后尝试使用命令,它回复了 2 个答案,例如,我使用了一个简单的“hello”命令,它会回复 "{ctx.author.mention} World" 但是,它现在会回复该消息 2 次而不是 1 次,我见过有人问某人是否有 on_message 事件,但从未继续。
我还尝试关闭我正在运行的每个 python 文件,用client.logout() 重新启动我的电脑,但仍然是同样的错误,有什么帮助吗?
【问题讨论】:
-
我觉得你可以删除
await self.client.process_commands(message)并且它会起作用
标签: python discord discord.py