discord.py 如何在没有管理角色权限的情况下授予用户角色
How to give user role without manage role permission in discord.py
我计划允许用户添加反应或键入命令以分配角色。如何在用户不需要管理角色权限的情况下分配角色?
from discord.ext import commands
client = commands.Bot(command_prefix='m.')
token = 'a token goes here'
@client.command()
async def hello_world(ctx):
await ctx.send("Hello world!")
client.run(token)
谢谢。
from discord.ext import commands
client = commands.Bot(command_prefix='m.')
token = 'a token goes here'
@client.command()
async def player(ctx):
role = discord.utils.get(ctx.guild.roles, name = "player")
if role is not None:
await ctx.author.add_roles(role)
client.run(token)
您的服务器中也需要有 player
角色。用户发送 m. player
作为示例,机器人将角色授予他。
我计划允许用户添加反应或键入命令以分配角色。如何在用户不需要管理角色权限的情况下分配角色?
from discord.ext import commands
client = commands.Bot(command_prefix='m.')
token = 'a token goes here'
@client.command()
async def hello_world(ctx):
await ctx.send("Hello world!")
client.run(token)
谢谢。
from discord.ext import commands
client = commands.Bot(command_prefix='m.')
token = 'a token goes here'
@client.command()
async def player(ctx):
role = discord.utils.get(ctx.guild.roles, name = "player")
if role is not None:
await ctx.author.add_roles(role)
client.run(token)
您的服务器中也需要有 player
角色。用户发送 m. player
作为示例,机器人将角色授予他。