我为我的Discord Bot添加了一个日志功能,所有命令都没有工作

发布于 2025-02-04 05:02:01 字数 390 浏览 1 评论 0 原文

我为我的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)

I added a log feature for my discord bot and after that all of the commands started not to work

this is the code that i added:

@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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

岁月蹉跎了容颜 2025-02-11 05:02:01

为什么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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文