我为我的Discord Bot添加了一个日志功能,所有命令都没有工作
我为我的Discord Bot添加了一个日志功能,然后所有命令开始不起作用,
这是我添加的代码:
@client.event
async def on_message(message, ctx):
ts = time.time()
st = datetime.datetime.fromtimestamp(ts).strftime('%Y-%m-%d %H:%M:%S')
with open("logs.txt", "a") as text_file:
print(f"<{st}> <{message.author}> <{message.id}> {message.content}", file=text_file)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
为什么on_message会使我的命令停止工作?
覆盖默认提供的默认提供的on_message禁止运行任何额外的命令。要解决此问题,请在on_message末尾添加 bot.process_commands(message)行。
考虑使用听众。在侦听器设置中,您无需手动调用 process_commands()
侦听器文档:
https> https:// discordpy。 ReadThEdthedocs.io/en/latest/latest/latest/latest/ext/latest/api.html#discord.ext.commands.bot.listen 示例。
在两个文档链接中提供了
Why does on_message make my commands stop working?
https://discordpy.readthedocs.io/en/latest/faq.html#why-does-on-message-make-my-commands-stop-working
Overriding the default provided on_message forbids any extra commands from running. To fix this, add a bot.process_commands(message) line at the end of your on_message.
Consider using a listener. In a listener setup you do not need to manually call process_commands()
Listener documentation:
https://discordpy.readthedocs.io/en/latest/ext/commands/api.html#discord.ext.commands.Bot.listen
Examples are provided in both documentation links.