向某人移动/添加不和谐角色

y53ybaqx  于 2022-10-22  发布在  Python
关注(0)|答案(1)|浏览(165)

我想创建一个提升cmd,当键入时,它会将成员提升到下一个级别,但我无法让它删除/添加他的角色

import discord
import os
from discord.utils import get

bot = discord.Bot(intents=discord.Intents.all())

admin = 990420666568278086

# roles

prospect = 869470046953537546
member = 869470100061814784
patched = 1003733917704134737

@bot.event
async def on_ready():
    print(f"{bot.user} is ready and online!")

@bot.slash_command(name="promote", description = "Promote people to the next rank")
async def promote(ctx, user: discord.Member):
    if ctx.author.get_role(admin):
        if user.get_role(prospect):
            await user.remove_roles(prospect)
            await user.add_roles(member, patched)

bot.run("DISCORD-TOKEN")
mtb9vblg

mtb9vblg1#

首先,get_role返回discord.Role。因此,如果你希望if语句为true,你应该将它与你的角色id进行比较。或者使用guild对象guild=ctx.guild,这样你就可以像user.get_role(prospect)==guild.get_role(prospect)这样做if语句
第二,请参考discord.Member。add_roles和discord.Member.remove_roles。他们两人都在争吵。角色作为参数。因此,您的代码应该类似于user.remove_roles(guild.get_role(prospect)),其中guild.get_role(prospect)返回discord
这就是您的代码应该是什么样子才能使其正常工作。快乐的编码!

async def promote(ctx, user: discord.Member):
    guild=ctx.guild
    if ctx.author.get_role(admin).id == admin:
        if user.get_role(prospect).id == prospect:
            await user.remove_roles(guild.get_role(prospect))
            await user.add_roles(guild.get_role(member), guild.get_role(patched))

相关问题