1 回答
TA贡献1809条经验 获得超8个赞
您需要将装饰器更改为 @client.command(pass_context=True). 成员名称被分配给context,保留member默认值。
@client.command(pass_context=True)
async def mute(context, member: discord.Member=None):
if not member:
await client.say('Please specify a member')
return
role = get(member.server.roles, name="Muted")
await client.add_roles(member, role)
await client.say(f'{member.mention} was muted.') # You forgot the f
另外,我可能只是让转换失败,然后处理错误:
@client.command(pass_context=True)
async def mute(ctx, member: discord.Member):
role = get(member.server.roles, name="Muted")
await client.add_roles(member, role)
await client.say(f'{member.mention} was muted.')
@mute.error:
async def mute_error(error, ctx):
if isinstance(error, ConversionError):
await client.send_message(ctx.message.channel, 'Please specify a member')
else:
raise error
添加回答
举报