英文:
TypeError: client.player.createQueue is not a function - How to fix this error in Discord.js bots? Discord.js/v.14
问题
Here is the translated part of your text:
"我在生成Discord的音乐机器人时遇到了问题,当运行机器人时显示以下错误(Discord.js/v.14)
错误:TypeError: client.player.createQueue is not a function
关于这个问题,我尝试过一些相关的研究,但没有找到能够帮助我的答案。
我相信getQueue()
也可能有问题,但我遇到的第一个问题是这个。
我想要一个解决这个问题的解决方案。"
英文:
I have a problem generating my music bot for discord, as it is displaying the following error when running the bot. (Discord.js/v.14)
Line(50): const queue = await client.player.createQueue(interaction.guild)
Code:
const { SlashCommandBuilder, EmbedBuilder } = require('@discordjs/builders')
const { QueryType } = require('discord-player')
module.exports = {
data: new SlashCommandBuilder()
.setName('play')
.setDescription('Plays a song.')
.addSubcommand((subcommand) => {
return subcommand
.setName('search')
.setDescription('Searches for a song.')
.addStringOption((option) => {
return option
.setName('searchterms')
.setDescription('Search keywords.')
.setRequired(true)
})
})
.addSubcommand((subcommand) => {
return subcommand
.setName('playlist')
.setDescription('Plays playlist from Youtube.')
.addStringOption((option) => {
return option
.setName('url')
.setDescription('Playlist URL.')
.setRequired(true)
})
})
.addSubcommand((subcommand) => {
return subcommand
.setName('song')
.setDescription('Plays song from Youtube.')
.addStringOption((option) => {
return option
.setName('url')
.setDescription('URL of the song.')
.setRequired(true)
})
}),
async execute({ client, interaction }) {
if (!interaction.member.voice.channel) {
await interaction.reply(
'You must be in a voice channel to uso this command.',
)
return
}
const queue = await client.player.createQueue(interaction.guild)
if (!queue.connection) await queue.connect(interaction.member.voice.channel)
const embed = new EmbedBuilder()
if (interaction.options.getSubcommand() === 'song') {
const url = interaction.options.getString('url')
const result = await client.player.search(url, {
requestedBy: interaction.user,
searchEngine: QueryType.YOUTUBE_VIDEO,
})
if (result.tracks.length === 0) {
await interaction.reply('No results found...')
return
}
const song = result.tracks[0]
await queue.addTrack(song)
embed
.setDescription(`Added **[${song.title}](${song.url})** to the queue.`)
.setThumbnail(song.thumbnail)
.setFooter({ text: `Duration: ${song.duration}` })
} else if (interaction.options.getSubcommand() === 'playlist') {
const url = interaction.options.getString('url')
const result = await client.player.search(url, {
requestedBy: interaction.user,
searchEngine: QueryType.YOUTUBE_PLAYLIST,
})
if (result.tracks.length === 0) {
await interaction.reply('No playlist found...')
return
}
const playlist = result.tracks[0]
await queue.addTracks(playlist)
embed
.setDescription(
`Added **[${playlist.title}](${playlist.url})** to the queue.`,
)
.setThumbnail(playlist.thumbnail)
.setFooter({ text: `Duration: ${playlist.duration}` })
} else if (interaction.options.getSubcommand() === 'search') {
const url = interaction.options.getString('searchterms')
const result = await client.player.search(url, {
requestedBy: interaction.user,
searchEngine: QueryType.AUTO,
})
if (result.tracks.length === 0) {
await interaction.reply('No results found...')
return
}
const song = result.tracks[0]
await queue.addTrack(song)
embed
.setDescription(`Added **[${song.title}](${song.url})** to the queue.`)
.setThumbnail(song.thumbnail)
.setFooter({ text: `Duration: ${song.duration}` })
}
if (!queue.playing) await queue.play()
await interaction.reply({
embeds: ,
})
},
}
Error: TypeError: client.player.createQueue is not a function
I've tried doing some research involving this issue, but haven't had any answers that help me.
I believe that there may also be a problem with getQueue(), but the first problem I encountered was this one.
I would like a solution to resolve this.
答案1
得分: 1
我假设你根据你的代码内容正在使用discord-player包。
自discord-player v5及以上版本以来,进行了一些内部更改,这意味着你应该使用player.nodes.create()
函数来创建一个新的队列。你可以在文档中找到它。同样,一些其他函数也根据新的GuildNodeManager进行了更改。
在这种情况下,应该是这样的:
const queue = await client.player.nodes.create(interaction.guild)
然而,由于你没有指定discord-player包的版本,我不能保证这对你来说是解决方案。如果你能提供你使用的discord-player包的版本,我可以编辑回答。
英文:
I assume that you are using the discord-player package based on your code contents.
Since discord-player v5 and above, some internal changes were made which means that you should use the player.nodes.create()
function to create a new queue. It can be found here in the documentation. Likewise, some other functions have changed too based on the new GuildNodeManager.
In this case, it would be:
const queue = await client.player.nodes.create(interaction.guild)
However, since you have not specified the version, I cannot guarantee that this is the solution for you. If you could provide what version of the discord-player package you are using, I could edit the answer.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论