【问题标题】:Discord bot commands execute multiple timesDiscord 机器人命令执行多次
【发布时间】:2020-07-08 19:08:54
【问题描述】:

一开始它有效,但不知何故它开始一次给出 4-5 次答案,知道为什么吗?

import discord
from discord.ext import commands

client = commands.Bot(command_prefix = '.')

@client.event
async def once_ready():
    print('Bot is ready.')

@client.event
async def on_member_join(member):
    print(f'{member} has joined the server.')

@client.event
async def on_member_remove(member):
    print(f'{member} has left the server.')

@client.command()
async def ping(ctx):
    await ctx.send('Pong!')

client.run('my token here')

【问题讨论】:

  • 我也尝试在我的服务器上重置机器人,但没有帮助。
  • 这能回答你的问题吗? stackoverflow.com/questions/60750793/…
  • 您好,感谢您的帮助。我确实有完全相同的问题,但我用 Atom 编写它,我看不到任何关闭已经运行的实例
  • 遗憾的是,我对 Atom 的了解还不够,无法帮助您解决这个问题。您最好的选择可能是在“原子”标签中询问。
  • 是的,我也尝试过 Reddit,但可能我只是要转移到另一个编译器,因为我和其他人不知道如何“修复”这个问题。 :C 谢谢你的帮助 :)

标签: python discord discord.py


【解决方案1】:

所以,问题是我无法在 Atom关闭已经在运行的机器人

  • 如果你添加我写在那里的代码(只有所有者可以 使用)将关闭已经运行的机器人(写 /shutdown in 不和谐服务器或任何你的前缀)。

但是,使用此代码保存机器人后,您可能需要重新启动 PC。

@client.command()
@commands.is_owner()
async def shutdown(ctx):
    await ctx.bot.logout()
  • 所以每次如果你想编辑你的命令,你写 /shutdown 并编辑它,然后你可以重新启动它。

我希望这对你有用,如果你有同样的问题,我可以提供帮助。

【讨论】:

  • 迟来的想法:您可以使用atexit 库进行拆解
猜你喜欢
  • 2018-05-06
  • 2021-10-06
  • 2021-08-14
  • 2019-12-14
  • 2019-12-14
  • 2020-01-25
  • 2021-01-01
  • 2021-07-31
  • 2021-03-11
相关资源
最近更新 更多