我想创建一个提升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")
1条答案
按热度按时间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这就是您的代码应该是什么样子才能使其正常工作。快乐的编码!