繁体   English   中英

Discord Bot Java API (net.dv8tion) 权限问题

[英]Discord Bot Java API (net.dv8tion) Permission Problems

我正在尝试制作一个可以添加/删除用户角色的 discord 机器人,但遗憾的是我遇到了一些权限问题。

API 可以找到: https://github.com/DV8FromTheWorld/JDA/

我很想听听有人知道该怎么做。 我还没有找到有同样问题的人。

错误的“退出”部分如下所示:

net.dv8tion.jda.api.exceptions.HierarchyException: Can't modify a role with higher or equal highest role than yourself! Role: R:unverified(1014845515776671764)
at net.dv8tion.jda.internal.entities.GuildImpl.checkPosition(GuildImpl.java:1866)
at net.dv8tion.jda.internal.entities.GuildImpl.addRoleToMember(GuildImpl.java:1535)
at Verify.onMessageReceived(Verify.java:29)

我已经检查过的内容:

  • https://discord.com/developers/applications - bot 部分中,我标记了 Privileged Gateway Intents 内容
  • 在服务器上我的机器人的邀请中,我检查了管理员权限
  • 在邀请中,除了 bot 和 application.commands 范围之外,我还检查了与公会相关的范围(但如果我只检查所有范围,则邀请链接不起作用,所以我专注于我认为重要的范围......无论如何)
  • 在源代码中,我启用了 GatewayIntents(请参见下面的源代码),但我认为不需要,因为我已经在前面的几点中设置了它们
  • 编辑:我还尝试使用在服务器上根本没有角色的新帐户执行 addRoleThingy -> 收到完全相同的错误
  • 编辑:当我想用机器人踢另一个帐户时,即使您需要更高的权限,它也会按预期工作......

主要.java:

import net.dv8tion.jda.api.JDA;
import net.dv8tion.jda.api.JDABuilder;
import net.dv8tion.jda.api.OnlineStatus;
import net.dv8tion.jda.api.entities.*;
import net.dv8tion.jda.api.hooks.ListenerAdapter;
import net.dv8tion.jda.api.requests.GatewayIntent;
import javax.security.auth.login.LoginException;


public class Main extends ListenerAdapter {
    public static Channel verifyingChannel = null;
    public static Role unverified = null;
    public static Role verified = null;

    public static void main(String[] args) throws LoginException {

        String token = "MTAxNDc5NDM3NTc5ODIwNjU2NA.GbfY1_.xBGsGKK5Ox1jzFVYwIp_cMU3kMcOvNnq2dKOQM";
        JDABuilder builder = JDABuilder.createDefault(token);

        builder.enableIntents(GatewayIntent.GUILD_MEMBERS, GatewayIntent.MESSAGE_CONTENT,GatewayIntent.GUILD_PRESENCES);
        builder.setStatus(OnlineStatus.ONLINE);
        builder.setActivity(Activity.listening("the sound of life"));

        builder.setMemberCachePolicy(MemberCachePolicy.ALL);
        builder.setChunkingFilter(ChunkingFilter.ALL);
        builder.enableCache(CacheFlag.ROLE_TAGS);
        JDA bot = builder.build().awaitReady();
        bot.addEventListener(new Verify());

        // don't worry about the next one, it adds some commands that just work already
        bot.addEventListener(new Commander(bot));

        System.out.println("Bot is online!");

    }

}

验证.java

import net.dv8tion.jda.api.entities.Channel;
import net.dv8tion.jda.api.entities.Member;
import net.dv8tion.jda.api.entities.TextChannel;
import net.dv8tion.jda.api.events.guild.member.GuildMemberJoinEvent;
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
import net.dv8tion.jda.api.hooks.ListenerAdapter;

public class Verify extends ListenerAdapter {

    public Verify(){}

    @Override
    public void onGuildMemberJoin(GuildMemberJoinEvent event) {
        // later: implement the addRoleToMember funtion here
    }

    @Override
    public void onMessageReceived(MessageReceivedEvent event){
        // The Role Main.unverified is first set with a setup command in the Commander-Class, that part is not the problem
        event.getGuild().addRoleToMember(event.getMember(),Main.unverified).queue();
    }

}

您根本无法修改具有更高或相同权限的用户,如错误日志中所示。

我假设您是测试机器人的服务器上的管理员。
因此,您和机器人具有相同/相等的权限,这违背了...

...“您根本无法修改具有更高或相同权限的用户,如错误日志中所示”



我建议您邀请另一个用户到服务器并给他较低的权限。 如果这样做,机器人应该能够毫无问题地修改新用户。

所以,为了最终解决我的问题,我只是重新安排了服务器上的角色。 在服务器属性中,机器人角色必须高于我想要应用的角色。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM