此交互失败 - Discord.js
This interaction failed - Discord.js
我正在制作一个带有保存按钮的 discord 斜杠命令 nowplaying
,并发送当前正在用户的 dm 中播放的音乐。我设法创建了可以正常工作的按钮,但我的问题是在单击“保存歌曲”按钮后,它显示 “此交互失败” 尽管按钮正常工作,但它发送了当前正在播放的音乐的嵌入。有人可以帮助我为什么会说那个错误吗?
节点: v17.7.2
不和谐:^13.2.0
我的 InteractionCreate
按钮事件 “保存歌曲”
const client = require("../index");
const { MessageEmbed } = require('discord.js');
const ee = require('../config.json');
client.on("interactionCreate", async (interaction) => {
// Slash Command Handling
if (interaction.isCommand()) {
await interaction.deferReply({ ephemeral: false }).catch(() => {});
const cmd = client.slashCommands.get(interaction.commandName);
if (!cmd)
return interaction.followUp({ content: "An error has occured " });
const args = [];
for (let option of interaction.options.data) {
if (option.type === "SUB_COMMAND") {
if (option.name) args.push(option.name);
option.options?.forEach((x) => {
if (x.value) args.push(x.value);
});
} else if (option.value) args.push(option.value);
}
interaction.member = interaction.guild.members.cache.get(interaction.user.id);
cmd.run(client, interaction, args);
}
// Context Menu Handling
if (interaction.isContextMenu()) {
await interaction.deferReply({ ephemeral: false });
const command = client.slashCommands.get(interaction.commandName);
if (command) command.run(client, interaction);
}
//Save Song button function
if (interaction.isButton()){
const queue = client.distube.getQueue(interaction.guildId);
switch (interaction.customId) {
case 'saveTrack': {
if (!queue || !queue.playing){
return interaction.followUp({ content: `No music currently playing. ❌`, ephemeral: true, components: [] });
} else {
const song = queue.songs[0];
const but_save = new MessageEmbed()
.setColor(ee.color)
.setTitle(client.user.username + " - Save Track")
.setThumbnail(client.user.displayAvatarURL())
.addField(` Track`, `\`${song.name}\``)
.addField(`⏳ Duration`, `\`${song.formattedDuration}\``, true)
.addField(` URL`, `${song.url}`)
.addField(`㊗ Saved Server`, `\`${interaction.guild.name}\``)
.addField(`➡ Requested By`, `${song.user}`, true)
.setTimestamp()
.setFooter({ text: 'H_M Save Music!', iconURL: interaction.user.displayAvatarURL({ dynamic: true }) });
interaction.user.send({ embeds: [but_save ] }).then(() => {
interaction.followUp({ content: `✅ | I sent the name of the music via private message.`, ephemeral: true }).catch(e => { })
}).catch(error => {
interaction.followUp({ content: `❌ | Unable to send you private message.`, ephemeral: true }).catch(e => { })
});
}
}
}
}
});
这是我的 nowplaying.js
const { MessageEmbed, MessageActionRow, MessageButton } = require('discord.js');
const ee = require('../../config.json');
const Format = Intl.NumberFormat();
const status = queue =>
`Volume: \`${queue.volume}%\` | Filters: \`${queue.filters.join(', ') || 'Off'}\` | Loop: \`${
queue.repeatMode ? (queue.repeatMode === 2 ? 'Playlist' : 'Song') : 'Off'
}\` | Autoplay: \`${queue.autoplay ? 'On' : 'Off'}\``
module.exports = {
name: "nowplaying",
description: "Shows the current song playing",
usage: "nowplaying",
run: async (client, interaction, args) => {
const queue = client.distube.getQueue(interaction);
const song = queue.songs[0];
const embed = new MessageEmbed()
.setColor(ee.color)
.setAuthor({name: 'Now playing...', iconURL: 'https://i.imgur.com/81ig9jl.jpg'})
.setDescription(`[${song.name}](${song.url})`)
.setThumbnail(song.thumbnail)
.addField(" | Status", `${status(queue).toString()}`, false)
.addField(' | Listens', `${Format.format(song.views)}`, true)
.addField(' | Prefer', `${Format.format(song.likes)}`, true)
.addField('⌛ | Played', `${queue.formattedCurrentTime} / ${song.formattedDuration}`, true)
.addField(' | Download link', `[Click here](${song.streamURL})`, true)
.addField(" | Requested by",` ${song.user}`, true)
const saveButton = new MessageButton();
saveButton.setLabel('Save Song');
saveButton.setCustomId('saveTrack');
saveButton.setStyle('SUCCESS');
const row = new MessageActionRow().addComponents(saveButton);
interaction.followUp({embeds: [embed], components: [row] });
}
}
将大小写切换为您的 ID 后,您需要 defer
与 await interaction.deferReply()
的互动,如果您想要它是一个短暂的消息,则可以选择 await interaction.deferReply({ ephemeral: true })
。应该等待这条线。
我正在制作一个带有保存按钮的 discord 斜杠命令 nowplaying
,并发送当前正在用户的 dm 中播放的音乐。我设法创建了可以正常工作的按钮,但我的问题是在单击“保存歌曲”按钮后,它显示 “此交互失败” 尽管按钮正常工作,但它发送了当前正在播放的音乐的嵌入。有人可以帮助我为什么会说那个错误吗?
节点: v17.7.2
不和谐:^13.2.0
我的 InteractionCreate
按钮事件 “保存歌曲”
const client = require("../index");
const { MessageEmbed } = require('discord.js');
const ee = require('../config.json');
client.on("interactionCreate", async (interaction) => {
// Slash Command Handling
if (interaction.isCommand()) {
await interaction.deferReply({ ephemeral: false }).catch(() => {});
const cmd = client.slashCommands.get(interaction.commandName);
if (!cmd)
return interaction.followUp({ content: "An error has occured " });
const args = [];
for (let option of interaction.options.data) {
if (option.type === "SUB_COMMAND") {
if (option.name) args.push(option.name);
option.options?.forEach((x) => {
if (x.value) args.push(x.value);
});
} else if (option.value) args.push(option.value);
}
interaction.member = interaction.guild.members.cache.get(interaction.user.id);
cmd.run(client, interaction, args);
}
// Context Menu Handling
if (interaction.isContextMenu()) {
await interaction.deferReply({ ephemeral: false });
const command = client.slashCommands.get(interaction.commandName);
if (command) command.run(client, interaction);
}
//Save Song button function
if (interaction.isButton()){
const queue = client.distube.getQueue(interaction.guildId);
switch (interaction.customId) {
case 'saveTrack': {
if (!queue || !queue.playing){
return interaction.followUp({ content: `No music currently playing. ❌`, ephemeral: true, components: [] });
} else {
const song = queue.songs[0];
const but_save = new MessageEmbed()
.setColor(ee.color)
.setTitle(client.user.username + " - Save Track")
.setThumbnail(client.user.displayAvatarURL())
.addField(` Track`, `\`${song.name}\``)
.addField(`⏳ Duration`, `\`${song.formattedDuration}\``, true)
.addField(` URL`, `${song.url}`)
.addField(`㊗ Saved Server`, `\`${interaction.guild.name}\``)
.addField(`➡ Requested By`, `${song.user}`, true)
.setTimestamp()
.setFooter({ text: 'H_M Save Music!', iconURL: interaction.user.displayAvatarURL({ dynamic: true }) });
interaction.user.send({ embeds: [but_save ] }).then(() => {
interaction.followUp({ content: `✅ | I sent the name of the music via private message.`, ephemeral: true }).catch(e => { })
}).catch(error => {
interaction.followUp({ content: `❌ | Unable to send you private message.`, ephemeral: true }).catch(e => { })
});
}
}
}
}
});
这是我的 nowplaying.js
const { MessageEmbed, MessageActionRow, MessageButton } = require('discord.js');
const ee = require('../../config.json');
const Format = Intl.NumberFormat();
const status = queue =>
`Volume: \`${queue.volume}%\` | Filters: \`${queue.filters.join(', ') || 'Off'}\` | Loop: \`${
queue.repeatMode ? (queue.repeatMode === 2 ? 'Playlist' : 'Song') : 'Off'
}\` | Autoplay: \`${queue.autoplay ? 'On' : 'Off'}\``
module.exports = {
name: "nowplaying",
description: "Shows the current song playing",
usage: "nowplaying",
run: async (client, interaction, args) => {
const queue = client.distube.getQueue(interaction);
const song = queue.songs[0];
const embed = new MessageEmbed()
.setColor(ee.color)
.setAuthor({name: 'Now playing...', iconURL: 'https://i.imgur.com/81ig9jl.jpg'})
.setDescription(`[${song.name}](${song.url})`)
.setThumbnail(song.thumbnail)
.addField(" | Status", `${status(queue).toString()}`, false)
.addField(' | Listens', `${Format.format(song.views)}`, true)
.addField(' | Prefer', `${Format.format(song.likes)}`, true)
.addField('⌛ | Played', `${queue.formattedCurrentTime} / ${song.formattedDuration}`, true)
.addField(' | Download link', `[Click here](${song.streamURL})`, true)
.addField(" | Requested by",` ${song.user}`, true)
const saveButton = new MessageButton();
saveButton.setLabel('Save Song');
saveButton.setCustomId('saveTrack');
saveButton.setStyle('SUCCESS');
const row = new MessageActionRow().addComponents(saveButton);
interaction.followUp({embeds: [embed], components: [row] });
}
}
将大小写切换为您的 ID 后,您需要 defer
与 await interaction.deferReply()
的互动,如果您想要它是一个短暂的消息,则可以选择 await interaction.deferReply({ ephemeral: true })
。应该等待这条线。