@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 禁止不在公会中的用户。到目前为止,这是我的代码,它没有响应或给出任何错误。
答案 0 :(得分:0)
使用 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)```