简体   繁体   English

我想让机器人在 Discord 上发送一条消息,但它给了我 Java JDA 中的错误

[英]I want to make the bot send a message on Discord but it gives me Error in Java JDA

I wrote the code and it works at first, but when I type the command mentioned to the bot which is "$info" it shows me the error mentioned below.我编写了代码,一开始它可以工作,但是当我输入提到机器人的命令“$info”时,它向我显示了下面提到的错误。 Please I need help请我需要帮助

testbot class This is the class of the token and this code that works normally and makes the bot online without any problems, but the problem is in the second class testbot class 这是令牌的 class,此代码正常工作并使机器人在线没有任何问题,但问题出在第二个 class

package testbot1;

import javax.security.auth.login.LoginException;

import net.dv8tion.jda.api.JDA;

import net.dv8tion.jda.api.JDABuilder;

public class Testbot1 {

    public static JDA jda;
    public static String prefix = "$";

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

        JDA jda = JDABuilder.createDefault("The Token Here").build();
        
        jda.addEventListener(new commands());

    }
    
}

commands classThis is the class for the message that is supposed to appear when I type in discord $info, but it gives me the following problem and also tells me that the problem is from this line命令 classThis 是 class 用于在我输入 discord $info 时应该出现的消息,但它给了我以下问题,还告诉我问题出在这一行

event.getChannel().sendMessage(info.build()).queue();
package testbot1;

import net.dv8tion.jda.api.EmbedBuilder;
import net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent;
import net.dv8tion.jda.api.hooks.ListenerAdapter;

public class commands extends ListenerAdapter {
    public void onGuildMessageReceived(GuildMessageReceivedEvent event) {
        String[] args = event.getMessage().getContentRaw().split("\\s+");
        
        if (args[0].equalsIgnoreCase(Testbot1.prefix + "info")) {
            EmbedBuilder info = new EmbedBuilder();
            info.setTitle("ElhadedyBot");
            info.setDescription("Currently, this bot is for testing only");
            info.setColor(0xf45642);
            info.setFooter("Created by Youssefeka116", event.getMember().getUser().getAvatarUrl());
            
            event.getChannel().sendTyping().queue();
            event.getChannel().sendMessage(info.build()).queue();
            info.clear();
        }
    }
}

This is the error that appears when I type in Discord this command "$info"这是我输入 Discord 这个命令“$info”时出现的错误

[JDA MainWS-ReadThread] ERROR JDA - One of the EventListeners had an uncaught exception
net.dv8tion.jda.api.exceptions.InsufficientPermissionException: Cannot perform action due to a lack of Permission. Missing permission: MESSAGE_EMBED_LINKS
    at net.dv8tion.jda.internal.entities.AbstractChannelImpl.checkPermission(AbstractChannelImpl.java:329)
    at net.dv8tion.jda.internal.entities.AbstractChannelImpl.checkPermission(AbstractChannelImpl.java:320)
    at net.dv8tion.jda.internal.entities.TextChannelImpl.sendMessage(TextChannelImpl.java:358)
    at testbot1.commands.onGuildMessageReceived(commands.java:19)
    at net.dv8tion.jda.api.hooks.ListenerAdapter.onEvent(ListenerAdapter.java:445)
    at net.dv8tion.jda.api.hooks.InterfacedEventManager.handle(InterfacedEventManager.java:96)
    at net.dv8tion.jda.internal.hooks.EventManagerProxy.handleInternally(EventManagerProxy.java:88)
    at net.dv8tion.jda.internal.hooks.EventManagerProxy.handle(EventManagerProxy.java:70)
    at net.dv8tion.jda.internal.JDAImpl.handleEvent(JDAImpl.java:151)
    at net.dv8tion.jda.internal.handle.MessageCreateHandler.handleInternally(MessageCreateHandler.java:97)
    at net.dv8tion.jda.internal.handle.SocketHandler.handle(SocketHandler.java:36)
    at net.dv8tion.jda.internal.requests.WebSocketClient.onDispatch(WebSocketClient.java:952)
    at net.dv8tion.jda.internal.requests.WebSocketClient.onEvent(WebSocketClient.java:839)
    at net.dv8tion.jda.internal.requests.WebSocketClient.handleEvent(WebSocketClient.java:817)
    at net.dv8tion.jda.internal.requests.WebSocketClient.onBinaryMessage(WebSocketClient.java:990)
    at com.neovisionaries.ws.client.ListenerManager.callOnBinaryMessage(ListenerManager.java:385)
    at com.neovisionaries.ws.client.ReadingThread.callOnBinaryMessage(ReadingThread.java:276)
    at com.neovisionaries.ws.client.ReadingThread.handleBinaryFrame(ReadingThread.java:996)
    at com.neovisionaries.ws.client.ReadingThread.handleFrame(ReadingThread.java:755)
    at com.neovisionaries.ws.client.ReadingThread.main(ReadingThread.java:108)
    at com.neovisionaries.ws.client.ReadingThread.runMain(ReadingThread.java:64)
    at com.neovisionaries.ws.client.WebSocketThread.run(WebSocketThread.java:45)

net.dv8tion.jda.api.exceptions.InsufficientPermissionException: Cannot perform action due to a lack of Permission. net.dv8tion.jda.api.exceptions.InsufficientPermissionException:由于缺少权限而无法执行操作。 Missing permission: MESSAGE_EMBED_LINKS缺少权限:MESSAGE_EMBED_LINKS

This tells you everything.这告诉你一切。

You try to send an embed message with您尝试发送嵌入消息

event.getChannel().sendMessage(info.build()).queue();

However, bots need the permission MESSAGE_EMBED_LINKS to send embed messages.但是,机器人需要权限MESSAGE_EMBED_LINKS才能发送嵌入消息。

Give the bot the permission in the channel or the guild.授予机器人在频道或公会中的权限。

Note that channel permissions overwrite guild permissions.请注意,频道权限会覆盖公会权限。

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

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