mirror of
https://code.chipmunk.land/Parker2991/NitoriBot/
synced 2026-12-05 08:35:39 -05:00
add embeds to discord commands along with fixing some bugs
This commit is contained in:
@@ -198,29 +198,54 @@ public final class Main implements EventListener {
|
||||
yeah yeah bitch at me for this hce, but for whatever reason it was acting like not all commands was
|
||||
registered even though they were
|
||||
*/
|
||||
List<CommandData> commands = new ArrayList<>();
|
||||
|
||||
for (CommandInfo command : bot.commandManager.commands) {
|
||||
scheduler.schedule(() -> {
|
||||
commands.add(
|
||||
Commands.slash(
|
||||
command.getAliases().getFirst(),
|
||||
command.getDescription()
|
||||
).addOption(OptionType.STRING, "content", "arguments")
|
||||
.setContexts(InteractionContextType.BOT_DM, InteractionContextType.GUILD,
|
||||
InteractionContextType.PRIVATE_CHANNEL)
|
||||
.setIntegrationTypes(
|
||||
IntegrationType.GUILD_INSTALL,
|
||||
IntegrationType.USER_INSTALL
|
||||
)
|
||||
if (discordClient.retrieveCommands().complete().isEmpty()) {
|
||||
LOGGER.warn("No Slash command are registered! registering them now...");
|
||||
List<CommandData> commands = new ArrayList<>();
|
||||
|
||||
for (CommandInfo command : bot.commandManager.commands) {
|
||||
scheduler.schedule(
|
||||
() -> {
|
||||
commands.add(Commands
|
||||
.slash(
|
||||
command
|
||||
.getAliases()
|
||||
.getFirst(),
|
||||
command.getDescription()
|
||||
)
|
||||
.addOption(
|
||||
OptionType.STRING,
|
||||
"content",
|
||||
"arguments"
|
||||
)
|
||||
.setContexts(
|
||||
InteractionContextType.BOT_DM,
|
||||
InteractionContextType.GUILD,
|
||||
InteractionContextType.PRIVATE_CHANNEL
|
||||
)
|
||||
.setIntegrationTypes(
|
||||
IntegrationType.GUILD_INSTALL,
|
||||
IntegrationType.USER_INSTALL
|
||||
)
|
||||
|
||||
);
|
||||
},
|
||||
2500,
|
||||
TimeUnit.MILLISECONDS
|
||||
);
|
||||
}, 2500, TimeUnit.MILLISECONDS);
|
||||
}
|
||||
}
|
||||
|
||||
scheduler.schedule(() -> {
|
||||
discordClient.updateCommands().addCommands(commands).queue();
|
||||
}, 3000, TimeUnit.MILLISECONDS);
|
||||
scheduler.schedule(
|
||||
() -> {
|
||||
discordClient
|
||||
.updateCommands()
|
||||
.addCommands(commands)
|
||||
.queue();
|
||||
},
|
||||
3000,
|
||||
TimeUnit.MILLISECONDS
|
||||
);
|
||||
}
|
||||
discordClient.addEventListener(new SlashCommandEvent(bot));
|
||||
} catch (Exception e) {
|
||||
LOGGER.error(
|
||||
|
||||
+11
-4
@@ -5,12 +5,16 @@ import land.chipmunk.parker2991.nitoribot.nightofnights.NitoriBot;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.data.PlayerProfileData;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.data.chat.ChatType;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.data.chat.ParsedChatType;
|
||||
import net.dv8tion.jda.api.EmbedBuilder;
|
||||
import net.dv8tion.jda.api.entities.MessageEmbed;
|
||||
import net.dv8tion.jda.api.events.GenericEvent;
|
||||
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
|
||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
import static land.chipmunk.parker2991.nitoribot.nightofnights.util.ComponentUtil.componentToAnsi;
|
||||
|
||||
public record CommandSource(
|
||||
@@ -43,15 +47,18 @@ public record CommandSource(
|
||||
);
|
||||
}
|
||||
case CommandMessageSource.DISCORD -> {
|
||||
final String message = "```ansi\n" + componentToAnsi(component) + "\n```";
|
||||
final MessageEmbed embed = new EmbedBuilder()
|
||||
.setColor(Color.BLUE)
|
||||
.addField("Output", message, false).build();
|
||||
|
||||
if (discordEvent instanceof MessageReceivedEvent event) {
|
||||
final String message = "```ansi\n" + componentToAnsi(component) + "\n```";
|
||||
event
|
||||
.getMessage()
|
||||
.reply(message)
|
||||
.replyEmbeds(embed)
|
||||
.queue();
|
||||
} else if (discordEvent instanceof SlashCommandInteractionEvent event) {
|
||||
final String message = "```ansi\n" + componentToAnsi(component) + "\n```";
|
||||
event.reply(message).queue();
|
||||
event.replyEmbeds(embed).queue();
|
||||
}
|
||||
}
|
||||
case CommandMessageSource.CONSOLE -> {
|
||||
|
||||
+1
-4
@@ -44,10 +44,7 @@ public final class SlashCommandEvent extends ListenerAdapter {
|
||||
command
|
||||
);
|
||||
|
||||
final String message = "```ansi\n" + componentToAnsi(output) + "\n```";
|
||||
event
|
||||
.reply(message)
|
||||
.queue();
|
||||
source.sendFeedback(bot, output);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+3
-1
@@ -91,10 +91,12 @@ public final class DiscordModule extends ListenerAdapter implements Listener {
|
||||
null
|
||||
);
|
||||
|
||||
bot.commandManager.executeString(
|
||||
final Component output = bot.commandManager.executeString(
|
||||
source,
|
||||
command
|
||||
);
|
||||
|
||||
source.sendFeedback(bot, output);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user