discord.py add_role() 尽管具有管理员角色,但仍出现缺少权限错误

问题描述 投票:0回答:1

我创建了几个角色来玩,管理员角色(机器人具有)和“超时”角色,其级别低于管理员角色。我已检查并重做机器人的权限,为其授予管理员权限,并使用不是服务器所有者的替代帐户进行测试。以上都没有产生任何结果,我仍然被拒绝许可。这是我的代码块:

@client.event
async def on_message(message):
    if message.author == client.user:
        return
    
    stopchecks = False
    if message.author not in moderationwhitelist:
        
        if message.mention_everyone:
            await message.reply("off to timeout with you")
            timeout = get(message.guild.roles, name="timeout")
            await message.author.add_roles(timeout)
            stopchecks = True

PS:客户端变量来自 client = discord.Client(intents=intents) 意图变量是discord.Intents.all()

PPS:我已经在堆栈溢出中搜索了答案,并尝试了建议的解决方案,但似乎没有一个起作用

预期结果是超时角色将应用于消息作者, 实际结果是角色未应用,机器人收到权限被拒绝错误

python discord.py
1个回答
0
投票

对我来说,代码完全有效。我包括一些调试打印。 这是我的完整代码:

import discord
from discord.utils import get

with open("token.txt") as file:
    token = file.read().strip()

moderationwhitelist = []

class aclient(discord.Client):
    def __init__(self):
        super().__init__(intents = discord.Intents.all())
            
client = aclient()

@client.event
async def on_message(message):
    if message.author == client.user:
        return
    
    stopchecks = False
    if message.author not in moderationwhitelist:
        print("b")
        if message.mention_everyone:
            print("c")
            await message.reply("off to timeout with you")
            timeout = get(message.guild.roles, name="timeout")
            await message.author.add_roles(timeout)
            stopchecks = True
    print("a")

client.run(token)

你能看看这是否有效吗?如果没有,请提供您的完整代码。 还要确保您的角色名称与所输入的内容完全一致

超时 = get(message.guild.roles, name="超时")

© www.soinside.com 2019 - 2024. All rights reserved.