Reputation: 33
So I tried to follow a tutorial to make my own music discord bot but when I try to launch it I got some problems I correctly installed the modules, and I've also made a json file that contain my token to make the bot,
and there is my code
const Discord = require('discord.js');
const client = new Discord.Client();
const DisTube = require('distube');
const distube = new DisTube(client, { searchSongs: false, emitNewSongs: true });
const { token } = require('./info.json');
const prefix = '!';
client.on("ready", () => {
console.log('${client.user.tag} va venir faire mousser tout ça!');
});
client.on("message", async(message) => {
if (message.author.bot) return;
if (!message.content.startsWith(prefix)) return;
const args = message.content.slice(prefix.length).trim().split(/ +/g);
const command = args.shift();
const status = (queue) => `Volume: \`${queue.volume}%\` | Filter: \`${queue.filter || "Off"}\` | Loop: \`${queue.repeatMode ? queue.repeatMode == 2 ? "All Queue" : "This Song" : "Off"}\` | Autoplay: \`${queue.autoplay ? "On" : "Off"}\``;
distube
.on("playSong", (message, queue, song) => message.channel.send(
`Joue :musical_note: et nique Brian \`${song.name}\` - \`${song.formattedDuration}\`\nDemandé par: ${song.user}\n${status(queue)}`
))
.on("addSong", (message, queue, song) => message.channel.send(
`Ajoutée! ${song.name} - \`${song.formattedDuration}\` to the queue by ${song.user}`
))
.on("playList", (message, queue, playlist, song) => message.channel.send(
`Joue :musical_note: \`${playlist.name}\` playlist (${playlist.songs.length} songs).\nDemandé par: ${song.user}\nJoue mtn \`${song.name}\` - \`${song.formattedDuration}\`\n${status(queue)}`
))
.on("addList", (message, queue, playlist) => message.channel.send(
`Ajouté \`${playlist.name}\` playlist (${playlist.songs.length} songs) to queue\n${status(queue)}`
))
.on("searchResult", (message, result) => {
let i = 0;
message.channel.send(`**Choisi en dessous**\n${result.map(song => `**${++i}**. ${song.name} - \`${song.formattedDuration}\``).join("\n")}\n*Tu as 60s pour choisir*`);
})
.on("searchCancel", (message) => message.channel.send(`Annulé batard`))
.on("error", (message, e) => {
console.error(e)
message.channel.send("Call Souf ça bug: " + e);
});
if (command =="play") {
if (!message.member.voice.channel) return message.channel.send('Tu ne peux pas entendre la douce mélodie.');
if (!args[0]) return message.channel.send('Décide toi frère!');
distube.play(message, args.join(" "));
}
if (command =="stop") {
const bot = message.guild.members.cache.get(client.user.id);
if (!message.member.voice.channel) return message.channel.send('Tu ne peux pas entendre la douce mélodie.');
if (bot.voice.channel !== message.member.voice.channel) return message.channel.send('Tu est pas dans le même channel que moi');
distube.stop(message);
message.channel.send('Tu as arreté la musique');
}
});
client.login(token);
Upvotes: 2
Views: 106
Reputation: 36
In discord.js v13
all bots are required to define their intents in the Client constructor
.
Example:
change your
const Discord = require('discord.js');
const client = new Discord.Client();
to
const {Client, Intents} = require('discord.js');
const client = new Client({intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES]});
You would obviously change the intents to what your bot would use.
More info can be found here
Upvotes: 2