Are you wondering How to make a music bot for the discord? Don’t worry, it is not as difficult as it sounds. Since you need a discord music bot to enjoy the music from your PC, learning How to make a music bot for the discord could be exactly what you need to enhance your Discord experience. Making a discord bot can be a very simple task but not easy as changing text color. All you need is an idea, basic coding skills, and creativity. This article will show you how to make music bot discord.
How To Make Music Bot Discord?
Making a music bot in Discord may seem like a big job, but in contrast, it just needs a little bit of patience and Coding skill. I will explain everything you need to know, from basic settings to coding. But if you just want your discord music bot to play music randomly, then scroll down. Before learning about How To Make Music Bot Discord, let’s take a look at all the tools required to complete the process of a music bot.
Tools To Make Music Bot In Discord
NODENPMFFMPEG
Also, read How to Check if Someone Left a Discord Server | Via PC, Mobile & Bot
How To Make Music Bot Discord With Coding?
How to make music bot discord with coding. This Discord guide will show you how to make a music bot for Discord. Steps to make music bot discord with coding are-
Create a new application on the discord Development Portal.Visit Portal and click on the new application.Give a name to the new application.Click on create button.Click the option bot tab & Click on add bot.
After creating the bot.Invite the bot.Navigate to the URL Generator and choose bot in the scope tap.Give permission to play music and read messages.Copy generated URL and paste it into the browser.Select the server and press authorizing button.
Create a project using the terminal.Create a directory using commands “mkdir musicbot && cd musicbot”Create two files in which we need to work “touch index.js && touch config.json”Use code and open with the commands “Code.”
Install some dependencies.Save the token of our bot and the prefix.For the token, you must revisit the discord developer portal and copy it from the bot section. We need to do this in our config.json file.
JavaScript Code To Make Music Bot Discord
How To Make Music Bot Discord Without Coding?
You want a music bot to add to your Discord chat, but you don’t want to do coding? I have a great solution that doesn’t require any programming skills.
const { prefix, token } = require(“./config.json”);
const ytdl = require(“ytdl-core”);
const client = new Discord.Client();
const queue = new Map();
client.once(“ready”, () => {
console.log(“Ready!”);
});
client.once(“reconnecting”, () => {
console.log(“Reconnecting!”);
});
client.once(“disconnect”, () => {
console.log(“Disconnect!”);
});
client.on(“message”, async message => {
if (message.author.bot) return;
if (!message.content.startsWith(prefix)) return;
const serverQueue = queue.get(message.guild.id);
if (message.content.startsWith(${prefix}play
)) {
execute(message, serverQueue);
return;
} else if (message.content.startsWith(${prefix}skip
)) {
skip(message, serverQueue);
return;
} else if (message.content.startsWith(${prefix}stop
)) {
stop(message, serverQueue);
return;
} else {
message.channel.send(“You need to enter a valid command!”);
}
});
async function execute(message, serverQueue) {
const args = message.content.split(” “);
const voiceChannel = message.member.voice.channel;
if (!voiceChannel)
return message.channel.send(
“You need to be in a voice channel to play music!”
);
const permissions = voiceChannel.permissionsFor(message.client.user);
if (!permissions.has(“CONNECT”) || !permissions.has(“SPEAK”)) {
return message.channel.send(
“I need the permissions to join and speak in your voice channel!”
);
}
const songInfo = await ytdl.getInfo(args[1]);
const song = {
title: songInfo.videoDetails.title,
url: songInfo.videoDetails.video_url,
};
if (!serverQueue) {
const queueContruct = {
textChannel: message.channel,
voiceChannel: voiceChannel,
connection: null,
songs: [],
volume: 5,
playing: true
};
queue.set(message.guild.id, queueContruct);
queueContruct.songs.push(song);
try {
var connection = await voiceChannel.join();
queueContruct.connection = connection;
play(message.guild, queueContruct.songs[0]);
} catch (err) {
console.log(err);
queue.delete(message.guild.id);
return message.channel.send(err);
}
} else {
serverQueue.songs.push(song);
return message.channel.send(${song.title} has been added to the queue!
);
}
}
function skip(message, serverQueue) {
if (!message.member.voice.channel)
return message.channel.send(
“You have to be in a voice channel to stop the music!”
);
if (!serverQueue)
return message.channel.send(“There is no song that I could skip!”);
serverQueue.connection.dispatcher.end();
}
function stop(message, serverQueue) {
if (!message.member.voice.channel)
return message.channel.send(
“You have to be in a voice channel to stop the music!”
);
if (!serverQueue)
return message.channel.send(“There is no song that I could stop!”);
serverQueue.songs = [];
serverQueue.connection.dispatcher.end();
}
function play(guild, song) {
const serverQueue = queue.get(guild.id);
if (!song) {
serverQueue.voiceChannel.leave();
queue.delete(guild.id);
return;
}
const dispatcher = serverQueue.connection
.play(ytdl(song.url))
.on(“finish”, () => {
serverQueue.songs.shift();
play(guild, serverQueue.songs[0]);
})
.on(“error”, error => console.error(error));
dispatcher.setVolumeLogarithmic(serverQueue.volume / 5);
serverQueue.textChannel.send(Start playing: **${song.title}**
);
}
client.login(token);
Steps to make music bot discord without coding are-
Also, read How to Set Up Discord Notifications for Facebook Gaming | On Discord & Facebook
Wrapping Up
Your perseverance paid off! Hopefully, this article helped you understand how to create a simple bot using the Discord API. Path of EX gives you a way “How to make music bot discord” without coding, also an easy way with coding.
Δ