交互失败-不协调



我正在制作一个带有保存按钮的不和谐斜线命令nowplaying,并在用户的dm中发送当前播放的音乐。我设法创建工作按钮,但我的问题是单击按钮"保存歌曲"它显示"此交互失败">虽然按钮工作,它发送当前播放的音乐嵌入。有人能告诉我为什么说这个错误吗?

节点:v17.7.2

不和:^ 13.2.0

myInteractionCreateevents for button"Save Song">

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 })。这句话应该等一下。

最新更新