自定义角色命令

时间:2020-12-24 16:07:37

标签: python discord discord.py

我需要关于 custom_role 命令的帮助。它应该为具有自定义名称和颜色的用户角色创建。

目前我只有:

@Bot.command()
async def custom_role(ctx):
    await ctx.guild.create_role(name = "role")

    emb = discord.Embed(description = "Role created!", color = 0x2ecc71)
    await ctx.send(embed = emb)

2 个答案:

答案 0 :(得分:2)

大功告成,您可以将角色名称和颜色作为参数传递,并使用指定的角色创建自定义角色:

@Bot.command()
async def custom_role(ctx, colour: str, *, name: str):
    colour = discord.Color(value=int(colour, 16))
    await ctx.guild.create_role(name = name, colour=colour)

    emb = discord.Embed(description = "Role created!", color = 0x2ecc71)
    await ctx.send(embed = emb)

用法示例(假设前缀为“!”):

!custom_role 0xa83232 test role # Creates a role named 'test role' in the color red

答案 1 :(得分:0)

也许这会有所帮助:

@Bot.command()
async def custom_role(ctx):
    permissions = discord.Permissions()
    await ctx.guild.create_role(name = 'role', colour = discord.Colour(0x2ecc71), permissions = permissions)

详细了解权限 here