简体   繁体   中英

Edit roles in discord bot

How to change color of role?

I'm a beginner so I don't know how to do it

Here's my Code:

import discord
from discord import utils
from discord.ext import commands
from config import settings
from discord.utils import get
bot = commands.Bot(command_prefix = settings['prefix'])
@bot.command()
async def hello(ctx):
    role_id = settings['roleid']
    
    await role.edit(colour = discord.Colour.orange())
bot.run(settings['token'])

You need to get the role with the role id using discord.utils.get or guild.get_role() . Then you can use await role.edit() .

@bot.command()
async def hello(ctx):
    role_id = settings['roleid']
    role = ctx.guild.get_role(int(role_id))
    await role.edit(colour = discord.Colour.orange())

If you want to use discord.utils.get , you can replace the role = ctx.guild.get_role(role_id) with role = discord.utils.get(ctx.guild.roles, id=role_id) .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM