Discord music bot issue - javascript

So I'm making a discord bot for my server and I'm having some issues with my music code!
The code is located here.
When I run the bot it works well, but when I do the !play command it throws the following error:
Error: FFMPEG not found
If someone could help me, I would be thankful. Thank you for your time.
client.on('message', async msg => {
if (msg.author.bot) return undefined;
if (!msg.content.startsWith(prefix)) return undefined;
const args = msg.content.split(' ');
if (msg.content.startsWith(`${prefix}play`)) {
const voiceChannel = msg.member.voiceChannel;
if (!voiceChannel) return msg.channel.send('Tens de estár numa sala para eu poder entrar!');
const permissions = voiceChannel.permissionsFor(msg.client.user);
if (!permissions.has('CONNECT')) {
return msg.channel.send('Só podes tocar musica no canal de Musica!')
}
if (!permissions.has('SPEAK')) {
return msg.channel.send('Não posso tocar musica nesse canal!')
}
try {
var connection = await voiceChannel.join();
} catch (error) {
console.error(`Não consigo entrar no canal porque: ${error}`);
return msg.channel.send(`Não consigo entrar no canal de voz: ${error}`);
}
const dispatcher = connection.playStream(ytdl(args[1]))
.on('end', () => {
console.log('Acabou a musica');
voiceChannel.leave();
})
.on('error', error => {
console.error(error);
});
dispatcher.setVolumeLogarithmic(5 / 5);
} else if (msg.content.startsWith(`${prefix}stop`)) {
if (msg.member.voiceChannel) return msg.channel.send('Não estás no canal');
msg.member.voiceChannel.leave();
return undefined;
}
});
client.login(token);`

It seems that you have not installed ffmpeg.
You can find an easy tutorial on how to install and add ffmpeg to path here:
https://www.wikihow.com/Install-FFmpeg-on-Windows
After you have installed ffmpeg, it will also need to be installed with npm like so:
npm install ffmpeg

Related

Discord.js 12.0.0 msg.content returning blank

I'm making a stats checker bot in discord.js v12.0.0 because I don't want to deal with slash commands and intents, just wanted this to be a quick little project that I throw together. But, after coding for a while a command I made didn't work, and I decided to console log msg.content to see if that was the issue. It shows as completely blank when I log msg.content, as well as logging msg itself. NO, I am not running a self bot, I read that doing that can also give this issue.
Images:
Code:
import Discord from 'discord.js';
const client = new Discord.Client();
import fetch from 'node-fetch';
client.on('ready', () => {
console.log(`online`);
});
let lb;
async function fet() {
await fetch("https://login.deadshot.io/leaderboards").then((res) => {
return res.json();
}).then((res) => {
lb = res;
})
}
client.on('message', async msg => {
console.log(msg)
let channel = msg.channel.id;
if (msg.author.id == client.user.id) return;
if (channel != 1015992080897679370) return;
await fet();
let r;
for (var x in lb.all.kills) {
if (msg.content.toLowerCase() == lb.all.kills[x].name.toLowerCase()) {
r = lb.all.kills[x].name;
}
}
if (!r) return msg.channel.send('Error: user not found')
})
client.login(token)
Discord enforced the Message Content privileged intent, since September 1st.
Here's the announcement from Discord Developers server (invite)
Source message: Discord Developers #api-announcements
You can fix this, but you do need to use intents...
const client = new Discord.Client({
ws: {
intents: [Discord.Intents.ALL, 1 << 15]
}
})
You also need to flip the Message Content intent switch in developer portal
It's much better to update to version 13+, v12 is deprecated and is easily broken.

Script of welcome / goodbye to discord js bot Error

He is giving me this script of welcome/goodbye to Discord error and he has already tried many things if someone helps me I would appreciate it very much, Thanks
module.exports = (client) => {
const channelIdA = '718596514305277972'
client.on('guildMemberAdd', (member) => {
console.log("Se ha unido una nueva persona al servidor TPA")
const messageA = `message`
const channel = (channelIdA)
channel.send(messageA)
})
}
module.exports = (client) => {
const channelIdB = '890891192995303424'
client.on('guildMemberRemove', (member) => {
console.log("Se ha salido una persona del servidor TPA")
const messageB = `message`
const channel = (channelIdB)
channel.send(messageB)
})
}
You are attempting to send a message to a channel by calling the .send() method. However, you are calling the method on a string. The send() method only exists on text based channels. To send a message to a specific channel, replace your message sending code with this
client.on("guildMemberAdd", members => {
client.channels.cache.get("REPLACE WITH CHANNEL ID").send("message")
});
client.on("guildMemberRemove", members => {
client.channels.cache.get("REPLACE WITH OTHER CHANNEL ID").send(" other message")
});
If the above does not work, try this:
(works without cache)
client.on("guildMemberAdd", async (member) => {
const channel = await client.channels.fetch("REPLACE WITH CHANNEL ID")
channel.send(`${member.user.username}, welcome`)
});
client.on("guildMemberRemove", async (member) => {
const channel = await client.channels.fetch("REPLACE WITH OTHER CHANNEL ID")
channel.send(`${member.user.username} has left`)
});
You should be getting the channel using this. If you already have the channel in cache (something happened in the channel after the bot started), you can use the channels cache as well.

Why since my switch to discord js 13, the messageCreate Event bug?

I explain my problem: I use a js file external to my commands for my Events and I have the impression that there are some things that do not work correctly in my messageCreate.js which however worked before with Discord .JS in version 12.
For example, when I want to return as soon as the bot sends a message it doesn't work via the messageCreate.js, I have to put it in all of my commands etc.
In my commands I noticed that the arguments do not work whereas before I had no problems. I was able to verify this by putting a
if(args == undefined) return console.log("test")
and the message "test" was displayed in the console as soon as I tried.
I put my code below, hoping you can help me. :)
the part of my index.js that deals with events:
fs.readdir("./Events/", (err, files) => {
Debug.logs(`[${chalk.cyan(moment(Date.now()).format('h:mm:ss'))}] ${chalk.cyan('Chargement des évènements ...')}`)
if (err) return Debug.logs(err)
files.forEach(async (file) => {
if (file.endsWith(".js")) {
const event = require(`./Events/${file}`)
let eventName = file.split(".")[0]
try {
bot.on(eventName, event.bind(null, bot))
delete require.cache[require.resolve(`./events/${file}`)]
Debug.logs(`[${chalk.cyan(moment(Date.now()).format('h:mm:ss'))}] ${chalk.green('Event Chargé :')} ${chalk.cyan(file)}`)
} catch (error) {
Debug.logs(error)
}
} else {
return
}
})
})
my messageCreate.js :
const env = process.env
const chalk = require('chalk')
const moment = require('moment')
const Debug = require('../utils/Debug')
const config = require("../config.json")
module.exports = async (bot, message) => {
if(message.channel.type === "DM"){
if(message.author.bot) return;
message.reply("Les commandes en **messages privés** sont actuellement **désactivées** !")
Debug.logs(`[${chalk.cyan(moment(Date.now()).format('h:mm:ss'))}] [${chalk.yellow(message.author.tag)}] a envoyé ${chalk.green(message.content)} en DM`)
}else{
if (!message.author.bot) {
if (message.content.startsWith(config.prefix)) {
const args = message.content.slice(config.prefix.length).trim().split(/ +/g)
const command = args.shift().toLowerCase()
const cmd = bot.commands.get(command)
if (cmd) {
await cmd.run(bot, message, args)
Debug.logs(`[${chalk.cyan(moment(Date.now()).format('h:mm:ss'))}] [${chalk.yellow(message.author.tag)}] a utilisé ${chalk.green(command)} ${chalk.cyan(args.join(" "))}`)
} else {
return
}
} else {
return
}
} else {
return
}
}
}
and one exemple of command who not work with messageCreate.js :
const Discord = require("discord.js");
module.exports.run = async (bot, message, config, args) => {
message.delete();
if(args == undefined) return console.log("wtf that not work ?")
}
module.exports.help = {
name:"test",
desc:"test commands !",
usage:"test",
group:"autre",
examples:"$test"
}
module.exports.settings = {
permissions:"false",
disabled:"false",
owner:"false"
}
as soon as I run the command with argument or without any argument, in both cases the console receives the message "wtf that not work?"
I hope you can help me! thanks in advance :)
Sorry if my english is bad but i'm french, not english !
In messageCreate.js, you call your command with the following:
// 3 arguments
await cmd.run(bot, message, args);
However, your command's run function is defined with 4 parameters:
async (bot, message, config, args) => {
// config = 'args', and args = undefined
}
To fix the issue, either:
Pass in a value for config, such as null:
await cmd.run(bot, message, null, args);
Make your function only have 3 parameters:
async (bot, message, args) => {
// ...
}

I have some problems with updating my bot from v11 to v12

I want to make a discord bot but I have some problems updating my bot from v11 to v12.
I need help by my kick and ban code
this is my Kick code
var member= message.mentions.members.first();
member.kick().then((member) => {
message.channel.send(member.displayName + " has been successfully kicked :point_right: ");
}).catch(() => {
message.channel.send("Access Denied");
});
}
}
and ban
var member= message.mentions.members.first();
member.ban().then((member) => {
message.channel.send(member.displayName + " has been successfully banned");
}).catch(() => {
message.channel.send("Access Denied");
});
}
}
and I couldn't find it on https://discordjs.guide/additional-info/changes-in-v12.html#before-you-start

Error running a javascript code(Discord music bot) - OPUS_ENGINE_MISSING

I'm trying to run a simple discord bot just to play a music, the bot is connectin to the channel perfectly but when it tries to play the music I recive this error:
(node:3028) UnhandledPromiseRejectionWarning: Error: OPUS_ENGINE_MISSING
My code:
var servers = {};
function play(connection, message) {
var server = servers[message.guild.id];
server.dispatcher = connection.playStream(YTDL(server.queue[0], {filter: "audioonly"}));
server.queue.shift();
server.dispatch.on("end", function() {
if(server.queue[0]) play(connection, message);
else connection.disconnect();
});
}
if(command === `${botSettings.prefix}play`)
{
if(!args[0]) {
message.channel.send("Please provide me a link!");
return;
}
if(!message.member.voiceChannel) {
message.channel.send("You must be in a voice channel!");
return;
}
if(!servers[message.guild.id]) servers[message.guild.id] = {
queue: []
};
var server = servers[message.guild.id];
server.queue.push(args[0]);
if(!message.guild.voiceConnection) message.member.voiceChannel.join().then(function(connection) {
play(connection, message);
});
}
You can install opusscript like this:
npm i opusscript
But I hear discord prefers node-opus
npm i node-opus
Hope this helps

Categories

Resources