【问题标题】:Discord,py Global Ban CommandDiscord,py 全球禁令命令
【发布时间】:2021-05-31 05:04:22
【问题描述】:

我一直在尝试制定一个全局禁止命令,该命令基本上会禁止用户访问我的机器人所在的每个不和谐服务器。我想指定我的机器人仅适用于拥有多个服务器的社区,因此它会通过添加全局禁止命令来防止黑客/滑雪者远离它。

这是我的代码。当我执行 gban userid 时,我没有收到任何错误,但它仍然没有禁止用户。有什么帮助吗?

@bot.command()
async def gban(ctx, user: discord.User):
  for guild in bot.guilds:
    await ctx.guild.ban(user)

【问题讨论】:

    标签: python discord.py


    【解决方案1】:

    你的错误是使用ctx.guild.ban,考虑一下,它只会禁止用户进入当前公会,而是在for循环中运行它。以下是您需要做的:

    @bot.command()
    async def gban(ctx, user: discord.User):
      for guild in bot.guilds:
        await guild.ban(user)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-03-23
      • 2021-05-22
      • 2020-11-24
      • 2020-10-09
      • 1970-01-01
      • 2021-09-06
      • 2022-01-12
      • 2021-06-28
      相关资源
      最近更新 更多