[英]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()
.则需要使用获得与角色ID的角色discord.utils.get
或guild.get_role()
Then you can use await role.edit()
.然后你可以使用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)
.如果要使用discord.utils.get
,可以将role = ctx.guild.get_role(role_id)
替换为role = ctx.guild.get_role(role_id)
role = discord.utils.get(ctx.guild.roles, id=role_id)
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.