So I've been working on a radio command on my discord bot but It keeps on getting errors like this and I was wondering if someone can assist me with the command
The error:
C:\Users\Matthew\OneDrive\Documents\Moria Calliope\node_modules\discord.js\src\structures\interfaces\InteractionResponses.js:149
if (!this.deferred && !this.replied) throw new Error(ErrorCodes.InteractionNotReplied);
^
Error [InteractionNotReplied]: The reply to this interaction has not been sent or deferred.
at SelectMenuInteraction.editReply (C:\Users\Matthew\OneDrive\Documents\Moria Calliope\node_modules\discord.js\src\structures\interfaces\InteractionResponses.js:149:48)
at InteractionCollector.<anonymous> (C:\Users\Matthew\OneDrive\Documents\Moria Calliope\interactions\slash\utilities\radio.js:90:22)
at InteractionCollector.emit (node:events:525:35)
at InteractionCollector.handleCollect (C:\Users\Matthew\OneDrive\Documents\Moria Calliope\node_modules\discord.js\src\structures\interfaces\Collector.js:119:14)
at processTicksAndRejections (node:internal/process/task_queues:96:5) {
code: 'InteractionNotReplied'
}
Here is the main code:
const {
ActionRowBuilder,
SelectMenuBuilder,
SlashCommandBuilder,
ActionRow,
} = require("discord.js");
const {
joinVoiceChannel,
createAudioResource,
createAudioPlayer,
} = require("@discordjs/voice");
const radioAssets = require("../../../Util/radioChannels.json");
module.exports = {
data: new SlashCommandBuilder()
.setName("radio")
.setDescription("📻 | Listen to the radio!"),
async execute(interaction) {
await interaction.deferReply({ ephemeral: true });
const channel = interaction.member.voice.channel;
if (!channel) {
return interaction.reply({
content: "You need to join a voice channel to do this!",
});
}
// Get the radio meta from the json file that has been declared
const getRadioChannel = radioAssets.channel.map((rad) => ({
// Then, re-formatted to label and value mapped object
label: rad.nativeName,
value: rad.name,
}));
// Make some select menus..
const radioMenu = new ActionRowBuilder().addComponents(
new SelectMenuBuilder()
.setCustomId("radioList")
.setPlaceholder("Select a radio channel!")
// Set it as the options, so the user can choose.
.addOptions(getRadioChannel)
);
const msg = await interaction.editReply({
content: "Please select one of the Radio channel that are listed below!",
components: [radioMenu],
fetchReply: true,
});
// Make some filter..
const filter = (i) => {
if (interaction.user.id !== i.user.id || i.customId !== "radioList") {
i.followUp({
content: "This menu is not for you!",
ephemeral: true,
});
return false;
} else {
return true;
}
};
// Collectors..
const collector = msg.createMessageComponentCollector({
filter,
time: 30000,
});
collector.on("collect", async (interaction) => {
// Find a radio name that match to the value that we set up before.
const findRadio = radioAssets.channel.find(
(rad) => rad.name === interaction.values.toString()
);
const player = createAudioPlayer();
// If we got the radio correctly, then get the radio uri.
const resource = createAudioResource(findRadio.uri);
// Make it connect to the voice channel
let connection = joinVoiceChannel({
guildId: interaction.guild.id,
channelId: channel.id,
adapterCreator: interaction.guild.voiceAdapterCreator,
selfDeaf: true,
selfMute: false,
});
// And this should play the audio
player.play(resource);
connection.subscribe(player);
// You can remove this, but msg "This interaction failed" should appeared, so if you keep this, that msg shouldn't appear
await interaction.editReply({
content:
"Radio has started successfully! Please do not undeafen me so I cannot hear your conversations while playing my music.",
ephemeral: true,
});
// And you are done.
await interaction.channel
.send({
content: `Started playing **${findRadio.nativeName}** in <#${channel.id}>`,
})
// Make the bot set suppressed to false if the initial command being used in stage channel
// KNOWN BUG: if the bot moved to stage channel it does not make the suppress to false.
.then((msg) => msg.guild.me.voice.setSuppressed(false))
// Error known because the user are not in a stage channel
// "You are only allowed to do this in stage channels"
.catch((err) => console.err(err));
});
},
};
Basically it keeps on saying that I haven't sent or deferred anything. I'm new to slash commands please help me-
After async execute(interaction)
you actually defer a reply by using await interaction.deferReply({ ephemeral: true });
, so that's what you want to remove!