Closed B3ni15 closed 6 months ago
@B3ni15 documentation does not state player.createQueue
or the ability to import player
from discord-player
.
// main file
const player = new Player(client);
// player events
// this event is emitted whenever discord-player starts to play a track
player.events.on('playerStart', (queue, track) => {
queue.metadata.channel.send(`Started playing **${track.title}**!`);
});
// your play command
const { useMainPlayer } = require('discord-player');
export async function execute(interaction) {
const player = useMainPlayer();
const channel = interaction.member.voice.channel;
if (!channel) return interaction.reply('You are not connected to a voice channel!'); // make sure we have a voice channel
const query = interaction.options.getString('query', true); // we need input/query to play
// let's defer the interaction as things can take time to process
await interaction.deferReply();
try {
const { track } = await player.play(channel, query, {
nodeOptions: {
// nodeOptions are the options for guild node (aka your queue in simple word)
metadata: interaction // we can access this metadata object using queue.metadata later on
}
});
return interaction.followUp(`**${track.title}** enqueued!`);
} catch (e) {
// let's return error if something failed
return interaction.followUp(`Something went wrong: ${e}`);
}
}
this is how a simple play command looks like.
Thanks.
But @twlite there is a other error:
The code:
const { MessageEmbed, } = require("discord.js");
const useMainPlayer = require('discord-player');
module.exports = {
name: "play",
description: "Zene lejátszása",
category: "song",
slash: true,
global: true,
error: async () => {},
options: [
{
name: "query",
description: "Zene hozzáadása a várólistához.",
type: 3,
required: true,
},
],
run: async (data) => {
const player = useMainPlayer();
const channel = data.interaction.member.voice.channel;
if (!channel) return data.interaction.reply('You are not connected to a voice channel!');
const query = data.interaction.options.getString('query', true);
await data.interaction.deferReply();
try {
const { track } = await player.play(channel, query, {
nodeOptions: {
metadata: data.interaction
}
});
return data.interaction.followUp(`**${track.title}** enqueued!`);
} catch (e) {
return data.interaction.followUp(`Something went wrong: ${e}`);
}
},
};
The error is self explanatory
Describe the bug When I type command, I get an error and it doesn't do anything when it should, because that's how it's written in the documentation.
The Error:
The code:
Please complete the following information: