簡體   English   中英

在 Discord bot 中編輯角色

[英]Edit roles in discord bot

如何改變角色的顏色?

我是初學者所以我不知道該怎么做

這是我的代碼:

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'])

則需要使用獲得與角色ID的角色discord.utils.getguild.get_role() 然后你可以使用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())

如果要使用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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM