Reputation:
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. 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
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
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"
[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)
Upvotes: 1
Views: 986
Reputation: 16447
net.dv8tion.jda.api.exceptions.InsufficientPermissionException: Cannot perform action due to a lack of Permission. Missing permission: 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.
Give the bot the permission in the channel or the guild.
Note that channel permissions overwrite guild permissions.
Upvotes: 2