【发布时间】:2020-09-26 17:51:07
【问题描述】:
我知道以前有人问过这个问题,但我的问题有点不同,我将如何创建一个命令来赋予其他人一个角色?例如
[p]giverole @user
会给他们一个角色吗?我知道如何使用 discord.py 为作者赋予角色,但无法弄清楚如何将其赋予所提到的人。任何帮助表示赞赏
【问题讨论】:
标签: discord discord.py
我知道以前有人问过这个问题,但我的问题有点不同,我将如何创建一个命令来赋予其他人一个角色?例如
[p]giverole @user
会给他们一个角色吗?我知道如何使用 discord.py 为作者赋予角色,但无法弄清楚如何将其赋予所提到的人。任何帮助表示赞赏
【问题讨论】:
标签: discord discord.py
您可以在这样的命令中使用参数:
@bot.command()
async def giverole(ctx, member: discord.Member=None):
# if no member is provided, the bot will give the role to the cmd author
if not member:
member = ctx.author
role = ctx.guild.get_role(112233445566778899) # role ID goes there
await member.add_roles(role)
await ctx.send(f"Successfully gave {member} the {role.name} role!")
这比使用on_message() 事件更可取,因为使用装饰器注册的命令时处理参数会容易得多。
参考资料:
Guild.get_role()Member.add_roles()【讨论】:
name 'discord' is not defined 你介意帮忙吗?