Buttons
Hi, I have this code here:
distube.on("playSong", (queue, song) => {
let embed = new Discord.MessageEmbed()
.setTitle("Playing song...")
.addField("Song", song.name)
.addField("Requested by", song.user.toString())
queue.textChannel.send({ embeds: [embed] });
songCount += 1;
console.log(chalk.red(songCount = ${songCount}));
let button1 = new Discord.MessageButton()
.setEmoji("❗")
.setLabel("Stop!")
.setStyle("SECONDARY")
.setCustomId(buttonstop,${song.user.id});
let row = new Discord.MessageActionRow()
.addComponents(button1);
queue.textChannel.send({ components: [row] });
client.on("interactionCreate", interaction => {
if (!interaction.isButton()) return;
if (interaction.customId.startsWith("buttonstop")) {
interaction.deferUpdate();
const voiceChannel = interaction.member.voice.channel;
if (!voiceChannel) {
return interaction.reply("You must be in a voice channel to execute this command");
}
const voiceChannelBot = interaction.guild.channels.cache.find(channel => channel.type == "GUILD_VOICE" && channel.members.has(client.user.id));
if (voiceChannelBot && voiceChannel.id !== voiceChannelBot.id) {
return interaction.reply("This bot is already in use in another voice chat");
}
try {
distube.stop(interaction);
} catch {
return interaction.reply("No songs playing or songs already stopped");
}
interaction.channel.send("Bye");
}
});
});
In this code there is a problem but I do not understand where, in the console I get this error: DiscordAPIError: Interaction has already been acknowledged.
7 Replies
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
You shouldnt nest an event inside another
If that distube event firest twice, you will create two interactionCreate events that will overlap each other
Instead, you should create a collector
And how should I do it
Well, read the guide I sent
I did so but it doesn't work:
const eventHandlers = {
playSong: (queue, song) => {
let embed = new Discord.MessageEmbed()
.setTitle("Playing song...")
.addField("Song", song.name)
.addField("Requested by", song.user.toString());
queue.textChannel.send({ embeds: [embed] });
songCount += 1;
console.log(
}, interactionCreate: interaction => { if (!interaction.isButton()) return; if (interaction.customId.startsWith("buttonstop")) { if (!interaction.isButton()) return; if (interaction.customId.startsWith("buttonstop")) { interaction.deferUpdate(); const voiceChannel = interaction.member.voice.channel; if (!voiceChannel) { return interaction.reply("You must be in a voice channel to execute this command"); } const voiceChannelBot = interaction.guild.channels.cache.find(channel => channel.type == "GUILD_VOICE" && channel.members.has(client.user.id)); if (voiceChannelBot && voiceChannel.id !== voiceChannelBot.id) { return interaction.reply("This bot is already in use in another voice chat"); }
try { distube.stop(interaction); } catch { return interaction.reply("No songs playing or songs already stopped"); } interaction.channel.send("Bye"); }
}; } } client.on("messageCreate", message => {
let button1 = new Discord.MessageButton() .setEmoji("❗") .setLabel("Stop!") .setStyle("SECONDARY") .setCustomId(
queue.textChannel.send({ components: [row] });
const collector = interaction.channel?.createMessageComponentCollector({ componentType: ComponentType.Button, }); collector?.on('collect', async (...args) => { const interaction = [...args][0]; await mainMenuHandler(interaction, collector); });
if (interaction.customId.startsWith("buttonstop")) { interaction.deferUpdate();
const voiceChannel = interaction.member.voice.channel; if (!voiceChannel) { return interaction.reply("You must be in a voice channel to run this command"); }
const voiceChannelBot = interaction.guild.channels.cache.find(channel => channel.type == "GUILD_VOICE" && channel.members.has(client.user.id)); if (voiceChannelBot && voiceChannel.id !== voiceChannelBot.id) { return interaction.reply("This bot is already in use in another voice chat"); } try { distube.stop(interaction);
} catch { return interaction.reply("No songs playing or songs already paused"); }
interaction.channel.send("Bye");
} }) I tried so but it gives me error
songCount = ${songCount}
);
let button1 = new Discord.MessageButton()
.setEmoji("❗")
.setLabel("Stop!")
.setStyle("SECONDARY")
.setCustomId(buttonstop,${song.user.id}
);
let row = new Discord.MessageActionRow()
.addComponents(button1);
currentInteraction = queue.textChannel.send({ components: [row] });
}, interactionCreate: interaction => { if (!interaction.isButton()) return; if (interaction.customId.startsWith("buttonstop")) { if (!interaction.isButton()) return; if (interaction.customId.startsWith("buttonstop")) { interaction.deferUpdate(); const voiceChannel = interaction.member.voice.channel; if (!voiceChannel) { return interaction.reply("You must be in a voice channel to execute this command"); } const voiceChannelBot = interaction.guild.channels.cache.find(channel => channel.type == "GUILD_VOICE" && channel.members.has(client.user.id)); if (voiceChannelBot && voiceChannel.id !== voiceChannelBot.id) { return interaction.reply("This bot is already in use in another voice chat"); }
try { distube.stop(interaction); } catch { return interaction.reply("No songs playing or songs already stopped"); } interaction.channel.send("Bye"); }
}; } } client.on("messageCreate", message => {
let button1 = new Discord.MessageButton() .setEmoji("❗") .setLabel("Stop!") .setStyle("SECONDARY") .setCustomId(
buttonstop,${song.user.id}
);
let row = new Discord.MessageActionRow()
.addComponents(button1);
queue.textChannel.send({ components: [row] });
const collector = interaction.channel?.createMessageComponentCollector({ componentType: ComponentType.Button, }); collector?.on('collect', async (...args) => { const interaction = [...args][0]; await mainMenuHandler(interaction, collector); });
if (interaction.customId.startsWith("buttonstop")) { interaction.deferUpdate();
const voiceChannel = interaction.member.voice.channel; if (!voiceChannel) { return interaction.reply("You must be in a voice channel to run this command"); }
const voiceChannelBot = interaction.guild.channels.cache.find(channel => channel.type == "GUILD_VOICE" && channel.members.has(client.user.id)); if (voiceChannelBot && voiceChannel.id !== voiceChannelBot.id) { return interaction.reply("This bot is already in use in another voice chat"); } try { distube.stop(interaction);
} catch { return interaction.reply("No songs playing or songs already paused"); }
interaction.channel.send("Bye");
} }) I tried so but it gives me error
Codeblocks:
```js
const Discord = require("discord.js");
// further code
```
becomes
Inline Code:
`console.log('inline!');` becomes
console.log('inline!');