Discord.py 破解禁令命令

Posted

技术标签:

【中文标题】Discord.py 破解禁令命令【英文标题】:Discord.py hack ban command 【发布时间】:2021-07-27 12:45:49 【问题描述】:
  @commands.command(aliases=['hban'])
  @commands.has_permissions(ban_members=True)
  @commands.cooldown(1,3,BucketType.user)
  async def hackban(self, ctx, userID:int):
      if userID in guild.members:
          embed = discord.Embed(description=":oxmark:  "+f"Unsuccessful, the user is in this guild. [-help ban]", color=discord.Color.orange())
          await ctx.reply(embed=embed, mention_author=False)

      else:
          await ctx.guild.ban(discord.Object(id=userID))
          embed = discord.Embed(title=":ocheckmark:  "+f"Successfully hack banned userID", color=discord.Color.orange())
          await ctx.reply(embed=embed, mention_author=False)

我正在制定一个 hackban 命令,该命令通过他们的 ID 禁止不在公会中的用户。到目前为止,这是我的代码,它没有响应或给出任何错误。

【问题讨论】:

这能回答你的问题吗? ***.com/questions/67330522/… @Dominik,我重写了命令,我现在要做的是,如果用户在公会中,它不会禁止他们,但它不起作用 【参考方案1】:

使用discord.User 代替discord.Object

@commands.command(aliases=['hban'])
@commands.has_permissions(ban_members=True)
@commands.cooldown(1, 3, BucketType.user)
async def hackban(self, ctx, user: discord.User):
    if user in ctx.guild.members:
        embed = discord.Embed(description=":oxmark:  "+f"Unsuccessful, the user is in this guild. [-help ban]", color=discord.Color.orange())
        await ctx.reply(embed=embed, mention_author=False)

    else:
        await ctx.guild.ban(user)
        embed = discord.Embed(title=":ocheckmark:  "+f"Successfully hack banned user.name", color=discord.Color.orange())
        await ctx.reply(embed=embed, mention_author=False)```

【讨论】:

我很确定禁止公会外的成员只能通过ID来完成。因此,我只希望它以 ID 作为输入。这个命令的全部目的是只禁止公会中不存在的人。 discord.User 对象会起作用,discord.Member 不会只传递它会起作用的 id。

以上是关于Discord.py 破解禁令命令的主要内容,如果未能解决你的问题,请参考以下文章

Discord 机器人帮助命令 [discord.py]

discord.py,同时使用斜杠命令和前缀

discord.py 块踢命令

Discord bot 运行命令两次 discord.py

找不到 discord.py 命令

我无法使用 discord.py 向我的 discord 机器人添加命令