[英]keep getting DiscordAPIError: Unknown Interaction when using reconlx's pagination for my queue command on my music bot in Discord.js
所以我有一個使用discord.js
編寫的音樂機器人,我決定對我的隊列命令使用分頁,以便我可以整齊地顯示整個隊列。 但是,在大多數情況下,我單擊按鈕切換頁面時,都會不斷收到 Unknown interaction discord API 錯誤。 我正在使用reconlx npm package
,這是我的隊列命令代碼:
const queue = distube.getQueue(message)
// embeds
const nothingPlaying = new MessageEmbed()
.setDescription('Nothing playing right now!');
if(!queue) return message.channel.send({ embeds: [nothingPlaying]} );
const queueEmbed1 = new MessageEmbed()
.setTitle('Current Queue:')
.setDescription(`${queue.songs
.map(
(song, id) =>
`**${id ? id : 'Playing'}**. ${song.name} - \`${
song.formattedDuration
}\``,
)
.slice(0, 20)
.join('\n')}`
)
const queueEmbed2 = new MessageEmbed()
.setTitle('Current Queue:')
.setDescription(`${queue.songs
.map(
(song, id) =>
`**${id ? id : 'Playing'}**. ${song.name} - \`${
song.formattedDuration
}\``,
)
.slice(20, 40)
.join('\n')}`
)
const queueEmbed3 = new MessageEmbed()
.setTitle('Current Queue:')
.setDescription(`${queue.songs
.map(
(song, id) =>
`**${id ? id : 'Playing'}**. ${song.name} - \`${
song.formattedDuration
}\``,
)
.slice(40, 60)
.join('\n')}`
)
const queueEmbed4 = new MessageEmbed()
.setTitle('Current Queue:')
.setDescription(`${queue.songs
.map(
(song, id) =>
`**${id ? id : 'Playing'}**. ${song.name} - \`${
song.formattedDuration
}\``,
)
.slice(60, 80)
.join('\n')}`
)
const queueEmbed5 = new MessageEmbed()
.setTitle('Current Queue:')
.setDescription(`${queue.songs
.map(
(song, id) =>
`**${id ? id : 'Playing'}**. ${song.name} - \`${
song.formattedDuration
}\``,
)
.slice(80, 100)
.join('\n')}`
)
const embeds = [
queueEmbed1,
queueEmbed2,
queueEmbed3,
queueEmbed4,
queueEmbed5,
]
pagination({
embeds: embeds,
channel: message.channel,
author:message.author,
fastSkip: true,
})
切片( NUMBERS )是顯示的歌曲位置,因此我為每個頁面設置了一個新的嵌入,我知道這很亂,但我想不出一種方法讓它更整潔,因為我對編程不太熟悉然而。 感謝您的幫助,我非常感謝。
分頁在網站或開發人員 web 頁面上使用得更多,嘗試在機器人上使用它是可能的,但更難和復雜。 我建議你使用discord-slider
。 在您的案例中,使用和處理面對 discord api 的問題更簡單。 你可以像這樣使用它:
const Discord = require('discord.js')
const client = new Discord.Client()
require("discord-buttons")(client);
require('discord-slider')(client);
// On a command :
channel.createSlider(userID, embedsArray, emojiNext, emojiBack)
例如,在您的情況下,您可以使用
channel.createSlider(message.author.id,embeds, "Next", "Back")
here
了解更多
--
PS :你似乎重復創建了相同的嵌入,只是做了一點點改變。 嘗試創建一個循環,相信我,它的效率更高,您甚至可以通過更改第 3 行的5
來選擇您想要的嵌入數!
let embeds = []
for (i = 0; i < 5; i++)
{
embeds.push(new Discord.MessageEmbed()
.setTitle('Current Queue:')
.setDescription(queue.songs
.map(
(song, id) =>
`**${id ? id : 'Playing'}**. ${song.name} - \`${
song.formattedDuration
}\``,
)
.slice((i*20), (i+1)*20)
.join('\n')
))
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.