@client.command( )
async def kick(ctx, user_name: discord.User, reason):
await ctx.guild.kick(user_name)
await ctx.send(f"""{user_name} has been kicked for {reason}""")
由于某种原因,有时我的机器人无法识别某些昵称。对于没有空格/一个字的昵称,机器人会毫无问题地将它们踢开。但是,对于带有下划线或空格的昵称,这是行不通的。我做错了什么吗?
答案 0 :(得分:0)
您的命令中有一些错误:
user_name
之后写一个句子,reason
只会将该句子的第一个单词作为值。要解决第一个问题:
#Change
async def kick(ctx, user_name: discord.User, reason):
#To
async def kick(ctx, user_name: discord.User, *, reason):
user_name
应该是Member
对象,而不是User
对象。这样,您的程序将仅在调用命令的服务器中查找指定的用户:
#Change
async def kick(ctx, user_name: discord.User, *, reason):
#To
async def kick(ctx, user_name: discord.Member, *, reason):
!kick @User You didn't respect the rules
!kick User You didn't respect the rules