我正试图这样做,如果我的一个版主去禁止一个用户,我的机器人会告诉他们,如果用户在采取行动之前离开了,他们是否不再在服务器上。这是我的ban命令的开始:
@client.command()
@commands.has_any_role("Head Honcho", "Discord Moderator")
async def ban(ctx, member : discord.Member, *, reason=None):
if member is None:
return await ctx.send("This member could not be found, or you did not provide an ID.")
if reason is None:
return await ctx.send("Please provide a reason for banning this user.")
if user not in ctx.guild.members:
return await ctx.send("This user is not in the server.")
if ctx.channel.id == 805651955841236993:
reaction_emote = ("<:Checkmark:820467149554319410>")
await ctx.message.add_reaction(reaction_emote)
我遇到的问题是这一点:
if user not in ctx.guild.members:
return await ctx.send("This user is not in the server.")
我尝试的东西似乎都没用。任何帮助都将不胜感激
您可以检查成员是否不在类似this的通道中
我有自己的方法
这将检查服务器中的成员
谢谢:D
您的代码实际上不需要检查,因为在定义函数参数时,已将参数
member
转换为discord.Member
对象。会员对象将始终在公会中,因此您不必担心会遇到无效用户。现在,如果希望捕获异常,可以使用on_command_error
事件来捕获相关问题 更多 >
编程相关推荐