【发布时间】:2021-08-01 03:04:09
【问题描述】:
假设有人在具有相同机器人的随机服务器中使用命令,它将检测该用户是否在他们所在的不同服务器中具有特定角色。
谁能告诉我如何/如果这是可能的?
【问题讨论】:
标签: python python-3.x discord discord.py
假设有人在具有相同机器人的随机服务器中使用命令,它将检测该用户是否在他们所在的不同服务器中具有特定角色。
谁能告诉我如何/如果这是可能的?
【问题讨论】:
标签: python python-3.x discord discord.py
您可以使用 commands.check 并使用其他公会的成员对象验证所需角色是否在 Member.roles 中。
此函数将获取一个公会和该公会中的一个角色,然后检查它是否在成员角色中
async def another_guild_role(ctx):
guild = bot.get_guild(12345) # change id here for wanted guild
role = guild.get_role(12345) # change id here for wanted role
member = guild.get_member(ctx.author.id)
# if member is not in bot chache make an API request
if not member:
member = guild.fetch_member(ctx.author.id)
return role in member.roles
这就是你将它包含在你的命令中的方式。
@bot.command()
@commands.check(another_guild_role)
async def test(ctx):
await ctx.send("Yes you have the role")
【讨论】: