【问题标题】:Discord.py hack ban commandDiscord.py 破解禁令命令
【发布时间】: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 禁止不在公会中的用户。到目前为止,这是我的代码,它没有响应或给出任何错误。

【问题讨论】:

标签: discord discord.py


【解决方案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。
猜你喜欢
  • 2020-09-11
  • 2018-11-07
  • 2020-05-26
  • 1970-01-01
  • 1970-01-01
  • 2021-04-06
  • 2018-11-12
  • 2022-01-23
  • 2021-05-11
相关资源
最近更新 更多