loading...
Cover image for How to set up a Discord music bot

Music Bot for Discord How to set up a Discord music bot

galnir profile image Nir Updated on ・4 min read

Setting up a music bot isn't easy since it requires lots of different things to be installed. In this guide I will list all the requirements and provide you with the code you need. Skipping a requirement will throw errors, so make sure you follow everything.

Let's start!

Create a bot

First we need to create the bot, go here and make sure you're logged in. Click on New Application and give your bot a name.
Go to the "Bot" tab on the left and click Add Bot under the "BUILD-A-BOT" tab. Reveal the token and save it because we will need it later.
Copy the client ID number on the "General Information" tab and paste it instead of the CLIENT_ID here https://discordapp.com/oauth2/authorize?&client_id=CLIENT_ID&scope=bot&permissions=8.
In the opened site choose the server you want the bot to join and continue. Now the bot has joined your server but since you didn't set him up he's offline for now.

Code Editor

A code editor let's us write and modify code. The code editor I use and recommend is Visual Studio Code.
You can also use other great editors like Sublime Text and Atom.

Node.js and npm

Node.js is a JavaScript runtime. It basically lets us run JavaScript code on our machine. We also use its package ecosystem, npm, which we will discuss next.
Download Node.js from its official website, discordjs requires v12 atleast.
To check if you installed it correctly, open your terminal(cmd or bash depending on which OS you are), and run node -v, you should get a number back. If you're struggling with installing Node, check out this guide.
Npm comes installed with Node.js, we will use npm later to install dependencies.

Git

Git is an open source version control system. It helps manage projects by keeping track of the entire history of a project and makes it easy to add features without worrying about breaking the entire program. We will use Git in order to obtain code for our bot from Github. Github is a hosting service for Git repos. You can learn more about Git and Github from this superb article.

If you're on Windows, install Git from here. For macOS users, install Xcode and then hit git --version, it'll prompt you to install it. If you're using Linux based OS, hit sudo dnf install git-all or sudo apt install git-all for debian.

FFmpeg

FFmpeg is a free and open-source project consisting of a vast software suite of libraries and programs for handling video, audio, and other multimedia files and streams. (Thanks Wikipedia)
FFmpeg helps us by converting video files to audio files that we use to play music through our bot.
Download it from its website.

Python 2.7

Python 2.7 is also required for this bot. Install the latest 2.7 version from here, look for the latest 2.7 version in the list. (At the time of writing, it is 2.7.16)

Youtube API key

In order to interact with the youtube API, you need to generate a key. Go through the steps here.

Next

After we've set up everything we need, it is time to run the bot!
Go to your terminal(cmd, git bash or bash), you probably see on the left that you are now in your user folder(C:\Users/"username"). Enter cd Desktop to go to your Desktop. Then 'git clone https://github.com/galnir/Master-Bot'. You are cloning(copying) my bot repository from GitHub so you can use its code.

Now fire up VScode. Select "File" in the top left of your screen, "Open Folder" and select the Master-Bot folder that was cloned into your Desktop.
You should see all the repos content on your editor.
Click on index.js. In line 7 change the id inside to your Discord user ID(see here) how to get it.
Now create a new file inside the bot folder, name it config.json and paste the following json into it:

{
  "prefix": "!",  // You can change the prefix to whatever you want it doesn't have to be - !
  "token": "Your-Bot-Token",
  "youtubeAPI": "youtube-api-key"
}

Replace "Your-Bot-Token" with the token you copied in the first section and youtube-api-key with the key you got from the Youtube section.

The last step is installing the dependencies using npm. Open your terminal(make sure you're on desktop or wherever you saved your bot repo) and hit npm install. Then enter node index.js and you should see your bot coming to life! You should be able to join a channel, use the !play command and your bot will play music.

That's it, in the repo's README you should be able to learn about the bot's commands.

If you want to learn how the music command works check out this guide I wrote.

Bot Repo: https://github.com/galnir/Master-Bot
Cover image by Malte Wingen :)

Posted on by:

Discussion

markdown guide
 

Can you help me?

(node:9104) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag --unhandled-rejections=strict (see nodejs.org/api/cli.html#cli_unhand...). (rejection id: 1)
(node:9104) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

Thats the error i get. Tried some trouble shooting, but didnt work. Also i dont hear any sound when my bot joins the channel... Is both the same problem or whats happening here? Pls help me, thanks.

 

Hey i have the same error. Could you please help me

 

Check again if you installed everything listed here, if something is missing it's not gonna work

 

Yes. I did everything like you said on top of this Blog. I followed every single step.

 

Hey, I tried a few things and I can't get the thing to run npm install properly.
gyp ERR! find VS
gyp ERR! find VS msvs_version not set from command line or npm config
gyp ERR! find VS VCINSTALLDIR not set, not running in VS Command Prompt
gyp ERR! find VS could not use PowerShell to find Visual Studio 2017 or newer
gyp ERR! find VS looking for Visual Studio 2015
gyp ERR! find VS - not found
gyp ERR! find VS not looking for VS2013 as it is only supported up to Node.js 8
gyp ERR! find VS
gyp ERR! find VS **************************************************************
gyp ERR! find VS You need to install the latest version of Visual Studio
gyp ERR! find VS including the "Desktop development with C++" workload.
gyp ERR! find VS For more information consult the documentation at:
gyp ERR! find VS github.com/nodejs/node-gyp#on-windows
gyp ERR! find VS **************************************************************
gyp ERR! find VS
gyp ERR! configure error
gyp ERR! stack Error: Could not find any Visual Studio installation to use
gyp ERR! stack at VisualStudioFinder.fail (C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\lib\find-visualstudio.js:121:47)
gyp ERR! stack at C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\lib\find-visualstudio.js:74:16
gyp ERR! stack at VisualStudioFinder.findVisualStudio2013 (C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\lib\find-visualstudio.js:351:14)
gyp ERR! stack at C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\lib\find-visualstudio.js:70:14
gyp ERR! stack at C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\lib\find-visualstudio.js:372:16
gyp ERR! stack at C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\lib\util.js:54:7
gyp ERR! stack at C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\lib\util.js:33:16
gyp ERR! stack at ChildProcess.exithandler (child_process.js:302:5)
gyp ERR! stack at ChildProcess.emit (events.js:210:5)
gyp ERR! stack at maybeClose (internal/child_process.js:1021:16)
gyp ERR! System Windows_NT 10.0.18362
gyp ERR! command "C:\Program Files\nodejs\node.exe" "C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\bin\node-gyp.js" "rebuild"
gyp ERR! cwd C:\Users\MadmouseKed\Desktop\Erika-Bot\Master-Bot\node_modules\node-opus
gyp ERR! node -v v12.13.1
gyp ERR! node-gyp -v v5.0.5
gyp ERR! not ok
npm WARN discord.js-commando@0.11.0-dev requires a peer of @types/better-sqlite3@5.0.0 but none is installed. You must install peer dependencies yourself.
npm WARN discord.js-commando@0.11.0-dev requires a peer of better-sqlite3@5.0.0 but none is installed. You must install peer dependencies yourself.
npm WARN discord.js-commando@0.11.0-dev requires a peer of discord.js@12.0.0 but none is installed. You must install peer dependencies yourself.
npm WARN discord.js-commando@0.11.0-dev requires a peer of sqlite@3.0.0 but none is installed. You must install peer dependencies yourself.
npm WARN master-bot@1.0.0 No repository field.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.9 (node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.9: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: ref@1.3.5 (node_modules\ref):
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: ref@1.3.5 install: node-gyp rebuild
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: Exit status 1

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! node-opus@0.3.2 install: node-gyp rebuild
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the node-opus@0.3.2 install script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\MadmouseKed\AppData\Roaming\npm-cache_logs\2019-12-03T15_45_58_318Z-debug.log

Hope you can help me out,
Thanks!
-Ked

 

According to stackoverflow it might be due to c++ build tools not being installed.
Take a look at this stackoverflow.com/questions/575414...

 

i get this when i try installing opus

gyp ERR! find VS
gyp ERR! find VS msvs_version not set from command line or npm config
gyp ERR! find VS VCINSTALLDIR not set, not running in VS Command Prompt
gyp ERR! find VS could not use PowerShell to find Visual Studio 2017 or newer
gyp ERR! find VS looking for Visual Studio 2015
gyp ERR! find VS - not found
gyp ERR! find VS not looking for VS2013 as it is only supported up to Node.js 8
gyp ERR! find VS
gyp ERR! find VS **************************************************************
gyp ERR! find VS You need to install the latest version of Visual Studio
gyp ERR! find VS including the "Desktop development with C++" workload.
gyp ERR! find VS For more information consult the documentation at:
gyp ERR! find VS github.com/nodejs/node-gyp#on-windows
gyp ERR! find VS **************************************************************
gyp ERR! find VS
gyp ERR! configure error
gyp ERR! stack Error: Could not find any Visual Studio installation to use
gyp ERR! stack at VisualStudioFinder.fail (C:\Users\UTENTE\AppData\Roaming\npm\node_modules\npm\node_modules\node-gyp\lib\find-visualstudio.js:121:47)
gyp ERR! stack at C:\Users\UTENTE\AppData\Roaming\npm\node_modules\npm\node_modules\node-gyp\lib\find-visualstudio.js:74:16
gyp ERR! stack at VisualStudioFinder.findVisualStudio2013 (C:\Users\UTENTE\AppData\Roaming\npm\node_modules\npm\node_modules\node-gyp\lib\find-visualstudio.js:351:14)
gyp ERR! stack at C:\Users\UTENTE\AppData\Roaming\npm\node_modules\npm\node_modules\node-gyp\lib\find-visualstudio.js:70:14
gyp ERR! stack at C:\Users\UTENTE\AppData\Roaming\npm\node_modules\npm\node_modules\node-gyp\lib\find-visualstudio.js:372:16
gyp ERR! stack at C:\Users\UTENTE\AppData\Roaming\npm\node_modules\npm\node_modules\node-gyp\lib\util.js:54:7
gyp ERR! stack at C:\Users\UTENTE\AppData\Roaming\npm\node_modules\npm\node_modules\node-gyp\lib\util.js:33:16
gyp ERR! stack at ChildProcess.exithandler (child_process.js:310:5)
gyp ERR! stack at ChildProcess.emit (events.js:310:20)
gyp ERR! stack at maybeClose (internal/child_process.js:1021:16)
gyp ERR! System Windows_NT 10.0.18362
gyp ERR! command "D:\nodejs\node.exe" "C:\Users\UTENTE\AppData\Roaming\npm\node_modules\npm\node_modules\node-gyp\bin\node-gyp.js" "configure" "--fallback-to-build" "--module=D:\discord bot\node_modules\@discordjs\opus\prebuild\node-v72-napi-v3-win32-x64-unknown-unknown\opus.node" "--module_name=opus" "--module_path=D:\discord bot\node_modules\@discordjs\opus\prebuild\node-v72-napi-v3-win32-x64-unknown-unknown" "--napi_version=5" "--node_abi_napi=napi" "--napi_build_version=3" "--node_napi_label=napi-v3"
gyp ERR! cwd D:\discord bot\node_modules\@discordjs\opus
gyp ERR! node -v v12.16.3
gyp ERR! node-gyp -v v5.1.0
gyp ERR! not ok
node-pre-gyp ERR! build error
node-pre-gyp ERR! stack Error: Failed to execute 'D:\nodejs\node.exe C:\Users\UTENTE\AppData\Roaming\npm\node_modules\npm\node_modules\node-gyp\bin\node-gyp.js configure --fallback-to-build --module=D:\discord bot\node_module --node_abi_napi=napi --napi_build_version=3 --node_napi_label=napi-v3' (1)
node-pre-gyp ERR! stack at ChildProcess. (D:\discord bot\node_modules\@discordjs\node-pre-gyp\lib\util\compile.js:72:20)
node-pre-gyp ERR! stack at ChildProcess.emit (events.js:310:20)
node-pre-gyp ERR! stack at maybeClose (internal/child_process.js:1021:16)
node-pre-gyp ERR! stack at Process.ChildProcess._handle.onexit (internal/child_process.js:286:5)
node-pre-gyp ERR! System Windows_NT 10.0.18362
node-pre-gyp ERR! command "D:\nodejs\node.exe" "D:\discord bot\node_modules\@discordjs\node-pre-gyp\bin\node-pre-gyp" "install" "--fallback-to-build"
node-pre-gyp ERR! cwd D:\discord bot\node_modules\@discordjs\opus
node-pre-gyp ERR! node -v v12.16.3
node-pre-gyp ERR! node-pre-gyp -v v0.1.0
node-pre-gyp ERR! not ok
Failed to execute 'D:\nodejs\node.exe C:\Users\UTENTE\AppData\Roaming\npm\node_modules\npm\node_modules\node-gyp\bin\node-gyp.js configure --fallback-to-build --module=D:\discord bot\node_modules\@discordjs\opus\prebuild\node-v72-napi-v3-win32-x64-unknown-unknown\opus.node --module_name=opus --module_path=D:\discord bot\node_modules\@discordjs\opus\prebuild\node-v72-napi-v3-win32-x64-unknown-unknown --napi_version=5 --node_abi_napi=napi --napi_build_version=3 --node_napi_label=napi-v3' (1)
npm WARN discord-bot@1.0.0 No description
npm WARN discord-bot@1.0.0 No repository field.

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! @discordjs/opus@0.3.2 install: node-pre-gyp install --fallback-to-build
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the @discordjs/opus@0.3.2 install script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\UTENTE\AppData\Roaming\npm-cache_logs\2020-05-19T12_44_04_308Z-debug.log

 

internal/modules/cjs/loader.js:800
throw err;
^

Error: Cannot find module 'C:\Users\Truong Anh\Desktop\bot\index.js'
?[90m at Function.Module._resolveFilename (internal/modules/cjs/loader.js:797
:15)?[39m
?[90m at Function.Module._load (internal/modules/cjs/loader.js:690:27)?[39m
?[90m at Function.Module.runMain (internal/modules/cjs/loader.js:1047:10)?[39
m
?[90m at internal/main/run_main_module.js:17:11?[39m {
code: ?[32m'MODULE_NOT_FOUND'?[39m,
requireStack: []
}

this is my trouble errors . help me please !!

 

Have you installed everything I listed?

 

yes . i installed all thing in this post . but i use python 3.7.0 :/

 

Error: Could not find an Opus module! Please install node-opus or opusscript.
at new OpusStream (C:\Users\WunderKid\Desktop\Master-Bot\node_modules\prism-media\src\opus\Opus.js:41:13)
at new Decoder (C:\Users\WunderKid\Desktop\Master-Bot\node_modules\prism-media\src\opus\Opus.js:163:1)
at AudioPlayer.playOpusStream (C:\Users\WunderKid\Desktop\Master-Bot\node_modules\discord.js\src\client\voice\player\BasePlayer.js:79:23)
at VoiceConnection.play (C:\Users\WunderKid\Desktop\Master-Bot\node_modules\discord.js\src\client\voice\util\PlayInterface.js:74:28)
at VoiceConnection.onSessionDescription (C:\Users\WunderKid\Desktop\Master-Bot\node_modules\discord.js\src\client\voice\VoiceConnection.js:455:29)
at VoiceWebSocket.emit (events.js:198:13)
at VoiceWebSocket.onPacket (C:\Users\WunderKid\Desktop\Master-Bot\node_modules\discord.js\src\client\voice\networking\VoiceWebSocket.js:188:14)
at VoiceWebSocket.onMessage (C:\Users\WunderKid\Desktop\Master-Bot\node_modules\discord.js\src\client\voice\networking\VoiceWebSocket.js:139:19)
at WebSocket.onMessage (C:\Users\WunderKid\Desktop\Master-Bot\node_modules\ws\lib\event-target.js:120:16)
at WebSocket.emit (events.js:198:13)

 

Did you install node-opus?

npm install node-opus

 

I get an error when I try to install node opus. Can you suggest what I should do?

node-opus@0.3.3 install C:\Users\georg\Downloads\Master-Bot\node_modules\node-opus

node-gyp rebuild

C:\Users\georg\Downloads\Master-Bot\node_modules\node-opus>if not defined npm_config_node_gyp (node "C:\Program Files\nodejs\node_modules\npm\node_modules\npm-lifecycle\node-gyp-bin\....\node_modules\node-gyp\bin\node-gyp.js" rebuild ) else (node "C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\bin\node-gyp.js" rebuild )
gyp ERR! configure error
gyp ERR! stack Error: Command failed: C:\Users\georg\AppData\Local\Programs\Python\Python38-32\python.EXE -c import sys; print "%s.%s.%s" % sys.version_info[:3];
gyp ERR! stack File "", line 1
gyp ERR! stack import sys; print "%s.%s.%s" % sys.version_info[:3];
gyp ERR! stack ^
gyp ERR! stack SyntaxError: invalid syntax
gyp ERR! stack
gyp ERR! stack at ChildProcess.exithandler (child_process.js:294:12)
gyp ERR! stack at ChildProcess.emit (events.js:189:13)
gyp ERR! stack at maybeClose (internal/child_process.js:970:16)
gyp ERR! stack at Process.ChildProcess._handle.onexit (internal/child_process.js:259:5)
gyp ERR! System Windows_NT 10.0.17134
gyp ERR! command "C:\Program Files\nodejs\node.exe" "C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\bin\node-gyp.js" "rebuild"
gyp ERR! cwd C:\Users\georg\Downloads\Master-Bot\node_modules\node-opus
gyp ERR! node -v v10.15.3
gyp ERR! node-gyp -v v3.8.0
gyp ERR! not ok
npm WARN discord.js@12.0.0-dev requires a peer of @discordjs/uws@11.149.1 but none is installed. You must install peer dependencies yourself.
npm WARN discord.js@12.0.0-dev requires a peer of bufferutil@4.0.1 but none is installed. You must install peer dependencies yourself.
npm WARN discord.js@12.0.0-dev requires a peer of erlpack@discordapp/erlpack but none is installed. You must install peer dependencies yourself.
npm WARN discord.js@12.0.0-dev requires a peer of libsodium-wrappers@0.7.4 but none is installed. You must install peer dependencies yourself.
npm WARN discord.js@12.0.0-dev requires a peer of sodium@3.0.2 but none is installed. You must install peer dependencies yourself.
npm WARN discord.js@12.0.0-dev requires a peer of zlib-sync@0.1.4 but none is installed. You must install peer dependencies yourself.
npm WARN discord.js@12.0.0-dev requires a peer of zucc@0.1.0 but none is installed. You must install peer dependencies yourself.
npm WARN discord.js-commando@0.11.0-dev requires a peer of @types/better-sqlite3@5.0.0 but none is installed. You must install peer dependencies yourself.
npm WARN discord.js-commando@0.11.0-dev requires a peer of better-sqlite3@5.0.0 but none is installed. You must install peer dependencies yourself.
npm WARN discord.js-commando@0.11.0-dev requires a peer of discord.js@12.0.0 but none is installed. You must install peer dependencies yourself.
npm WARN discord.js-commando@0.11.0-dev requires a peer of sqlite@3.0.0 but none is installed. You must install peer dependencies yourself.
npm WARN prism-media@1.1.0 requires a peer of opusscript@0.0.6 but none is installed. You must install peer dependencies yourself.
npm WARN master-bot@1.0.0 No repository field.

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! node-opus@0.3.3 install: node-gyp rebuild
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the node-opus@0.3.3 install script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\georg\AppData\Roaming\npm-cache_logs\2019-10-30T20_20_37_834Z-debug.log

You are using python version 3.x and it requires python version 2.7

 

hi i have a error

  • c:\Users\imady\OneDrive\Desktop\bot-final.edition\index.js at Function.Module._resolveFilename (internal/modules/cjs/loader.js:793:17) at Function.Module._load (internal/modules/cjs/loader.js:686:27) at Module.require (internal/modules/cjs/loader.js:848:19) at require (internal/modules/cjs/helpers.js:74:18) at Object. (c:\Users\imady\OneDrive\Desktop\bot-final.edition\index.js:1:28) at Module._compile (internal/modules/cjs/loader.js:952:14) at Object.Module._extensions..js (internal/modules/cjs/loader.js:991:10) at Module.load (internal/modules/cjs/loader.js:811:32) at Function.Module._load (internal/modules/cjs/loader.js:723:14) at Function.Module.runMain (internal/modules/cjs/loader.js:1043:10)

end i have a error whit NPM code
extract: WARN tar ENOENT: no such file or directory, open 'C:\Users\imady\OneDrive\Desktop\bot-final.edition\node_modules.staging\@babel\types-

 

Did you install all the dependencies and other requirements?

 

ok i managed to settle my problem with friend but a new problem is before us
debugger listening on ws://127.0.0.1:4777/7ce98a6d-7418-49f0-acae-6553fff29399
For help, see: nodejs.org/en/docs/inspector

Debugger attached.
WaitingError: Cannot find module '../../config.json'
Require stack:

  • c:\Users\imady\OneDrive\Desktop\bot-final.edition\commands\gifs\animegif.js
  • c:\Users\imady\OneDrive\Desktop\bot-final.edition\node_modules\require-all\index.js
  • c:\Users\imady\OneDrive\Desktop\bot-final.edition\node_modules\discord.js-commando\src\registry.js
  • c:\Users\imady\OneDrive\Desktop\bot-final.edition\node_modules\discord.js-commando\src\client.js
  • c:\Users\imady\OneDrive\Desktop\bot-final.edition\node_modules\discord.js-commando\src\index.js
  • c:\Users\imady\OneDrive\Desktop\bot-final.edition\index.js at Function.Module._resolveFilename (internal/modules/cjs/loader.js:980:15) at Function.Module._load (internal/modules/cjs/loader.js:862:27) at Module.require (internal/modules/cjs/loader.js:1040:19) at require (internal/modules/cjs/helpers.js:72:18) at Object. (c:\Users\imady\OneDrive\Desktop\bot-final.edition\commands\gifs\animegif.js:2:22) at Module._compile (internal/modules/cjs/loader.js:1151:30) at Object.Module._extensions..js (internal/modules/cjs/loader.js:1171:10) at Module.load (internal/modules/cjs/loader.js:1000:32) at Function.Module._load (internal/modules/cjs/loader.js:899:14) at Module.require (internal/modules/cjs/loader.js:1040:19) for the debugger to disconnect...

debugger listening on ws://127.0.0.1:33350/4b02f0da-9828-4ed9-a1cd-5ba111b9b611
For help, see: nodejs.org/en/docs/inspector
Debugger attached.
Waiting foError: Cannot find module '../../config.json'
Require stack:

  • c:\Users\imady\OneDrive\Desktop\bot-final.edition\commands\gifs\animegif.js
  • c:\Users\imady\OneDrive\Desktop\bot-final.edition\node_modules\require-all\index.js
  • c:\Users\imady\OneDrive\Desktop\bot-final.edition\node_modules\discord.js-commando\src\registry.js
  • c:\Users\imady\OneDrive\Desktop\bot-final.edition\node_modules\discord.js-commando\src\client.js
  • c:\Users\imady\OneDrive\Desktop\bot-final.edition\node_modules\discord.js-commando\src\index.js
  • c:\Users\imady\OneDrive\Desktop\bot-final.edition\index.js at Function.Module._resolveFilename (internal/modules/cjs/loader.js:980:15) at Function.Module._load (internal/modules/cjs/loader.js:862:27) at Module.require (internal/modules/cjs/loader.js:1040:19) at require (internal/modules/cjs/helpers.js:72:18) at Object. (c:\Users\imady\OneDrive\Desktop\bot-final.edition\commands\gifs\animegif.js:2:22) at Module._compile (internal/modules/cjs/loader.js:1151:30) at Object.Module._extensions..js (internal/modules/cjs/loader.js:1171:10) at Module.load (internal/modules/cjs/loader.js:1000:32) at Function.Module._load (internal/modules/cjs/loader.js:899:14) at Module.require (internal/modules/cjs/loader.js:1040:19) r the debugger to disconnect...

is its this is the new error code

 

internal/modules/cjs/loader.js:305
throw err;
^

Error: Cannot find module 'C:\Users\Truong Anh\Desktop\bot1\index.js'. Please verify that the package.json has
a valid "main" entry
?[90m at tryPackage (internal/modules/cjs/loader.js:297:19)?[39m
?[90m at Function.Module._findPath (internal/modules/cjs/loader.js:528:18)?[39m
?[90m at Function.Module._resolveFilename (internal/modules/cjs/loader.js:784:27)?[39m
?[90m at Function.Module._load (internal/modules/cjs/loader.js:690:27)?[39m
?[90m at Function.Module.runMain (internal/modules/cjs/loader.js:1047:10)?[39m
?[90m at internal/main/run_main_module.js:17:11?[39m {
code: ?[32m'MODULE_NOT_FOUND'?[39m,
path: ?[32m'C:\Users\Truong Anh\Desktop\bot1\package.json'?[39m,
requestPath: ?[32m'C:\Users\Truong Anh\Desktop\bot1'?[39m
}

this is my trouble error
any suggestions to help me?

 

Can you help me?

throw err;
^

SyntaxError: C:\Master-Bot-master\config.json: Unexpected token / in JSON at position 24
at parse ()
at Object.Module._extensions..json (internal/modules/cjs/loader.js:1192:22)
at Module.load (internal/modules/cjs/loader.js:1002:32)
at Function.Module._load (internal/modules/cjs/loader.js:901:14)
at Module.require (internal/modules/cjs/loader.js:1044:19)
at require (internal/modules/cjs/helpers.js:77:18)
at Object. (C:\Master-Bot-master\index.js:4:27)
at Module._compile (internal/modules/cjs/loader.js:1158:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1178:10)
at Module.load (internal/modules/cjs/loader.js:1002:32)

don't know how to fix this... :(

 

You didn't place an api key correctly in config.json

 

SyntaxError: /home/danielfa/Master-Bot/config.json: Unexpected token / in JSON a t position 21
at parse ()
at Object.Module._extensions..json (internal/modules/cjs/loader.js:1152:22)
at Module.load (internal/modules/cjs/loader.js:982:32)
at Function.Module._load (internal/modules/cjs/loader.js:875:14)
at Module.require (internal/modules/cjs/loader.js:1022:19)
at require (internal/modules/cjs/helpers.js:72:18)
at Object. (/home/danielfa/Master-Bot/index.js:4:27)
at Module._compile (internal/modules/cjs/loader.js:1118:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1138:10)
at Module.load (internal/modules/cjs/loader.js:982:32)

 

Hi i have a problem, you can help me pls?

C:\Users\dayea\Desktop\Master-Bot>node index.js
internal/modules/cjs/loader.js:1274
throw err;
^

SyntaxError: C:\Users\dayea\Desktop\Master-Bot\config.json: Unexpected token / in JSON at position 23
at parse ()
[90m at Object.Module._extensions..json (internal/modules/cjs/loader.js:1271:22)[39m
[90m at Module.load (internal/modules/cjs/loader.js:1085:32)[39m
[90m at Function.Module._load (internal/modules/cjs/loader.js:950:14)[39m
[90m at Module.require (internal/modules/cjs/loader.js:1125:19)[39m
[90m at require (internal/modules/cjs/helpers.js:75:18)[39m
at Object. (C:\Users\dayea\Desktop\Master-Bot\index.js:4:45)
[90m at Module._compile (internal/modules/cjs/loader.js:1236:30)[39m
[90m at Object.Module._extensions..js (internal/modules/cjs/loader.js:1257:10)[39m
[90m at Module.load (internal/modules/cjs/loader.js:1085:32)[39m

C:\Users\dayea\Desktop\Master-Bot>node index.js

 

What should i do?

C:\Users\Enriko\Desktop\DiscordMusicBot\Master-Bot>node index.js
internal/modules/cjs/loader.js:985
throw err;
^

Error: Cannot find module 'discord.js-commando'
Require stack:

  • C:\Users\Enriko\Desktop\DiscordMusicBot\Master-Bot\index.js [90m at Function.Module._resolveFilename (internal/modules/cjs/loader.js:982:15)[39m [90m at Function.Module._load (internal/modules/cjs/loader.js:864:27)[39m [90m at Module.require (internal/modules/cjs/loader.js:1044:19)[39m [90m at require (internal/modules/cjs/helpers.js:77:18)[39m at Object. (C:\Users\Enriko\Desktop\DiscordMusicBot\Master-Bot\index.js:1:28) [90m at Module._compile (internal/modules/cjs/loader.js:1158:30)[39m [90m at Object.Module._extensions..js (internal/modules/cjs/loader.js:1178:10)[39m [90m at Module.load (internal/modules/cjs/loader.js:1002:32)[39m [90m at Function.Module._load (internal/modules/cjs/loader.js:901:14)[39m [90m at Function.executeUserEntryPoint as runMain[39m { code: [32m'MODULE_NOT_FOUND'[39m, requireStack: [ [32m'C:\Users\Enriko\Desktop\DiscordMusicBot\Master-Bot\index.js'[39m ] }
 

It says you didn't install discord.js-commando..

 

error

E:\Master-Bot-master>node index.js
internal/modules/cjs/loader.js:1184
throw err;
^

SyntaxError: E:\Master-Bot-master\config.json: Unexpected token / in JSON at pos
ition 21
at parse ()
←[90m at Object.Module._extensions..json (internal/modules/cjs/loader.js:1181
:22)←[39m
←[90m at Module.load (internal/modules/cjs/loader.js:996:32)←[39m
←[90m at Function.Module._load (internal/modules/cjs/loader.js:896:14)←[39m
←[90m at Module.require (internal/modules/cjs/loader.js:1036:19)←[39m
←[90m at require (internal/modules/cjs/helpers.js:72:18)←[39m
at Object. (E:\Master-Bot-master\index.js:4:27)
←[90m at Module._compile (internal/modules/cjs/loader.js:1147:30)←[39m
←[90m at Object.Module._extensions..js (internal/modules/cjs/loader.js:1167:1
0)←[39m
←[90m at Module.load (internal/modules/cjs/loader.js:996:32)←[39m

 

I have a problem when I run npm install in command prompt, it shows me this:

 
 

nvm, i fixed that but i have another problem

 

How can I install ffmpeg to debian?

 

sudo apt install ffmpeg

 

Hi i have a question the bot token i put in the in the index.js and cofig.json?

 

An error occurred while running the command: TypeError: fields.flat is not a function
You shouldn't ever receive an error like this.

why i get this error?

 

Hello ! I am really embarrased because I can't install node-opus... I have Python 2.7, but nothing. Same error as Madmouseked, npm tells me something about node-gyp.

Any idead ? Thank you 😊

 

Did you ever find a solution? I am having the same problem

 

If you have python 2.7 and everything that is required installed, the problem is probably about not running the terminal as admin or sudo(if you're using linux based OS).
Try to open the cmd(if windows) as admin, or run "sudo npm i node-opus" if on linux OS

 

Try to google that specific error, I have no idea what it can be :/

 

Thank you so much 💕 for the this tutorial.

 

My bot is online but when I play something It connects, then shows that it is playing music and then it disconnects

 

Then you must have skipped a step or done something not right, go over the steps again and make sure you install each requirement

 
 

That's probably a network issue on your end.. all npm does is install packages

 

Hello, i did create a config.json file but it still says this even though i saved everything:

C:\Users\me\Downloads\sateenkaari>node .
internal/modules/cjs/loader.js:964
throw err;
^

Error: Cannot find module '../../config.json'
Require stack:

  • C:\Users\me\Downloads\sateenkaari\index.js at Function.Module._resolveFilename (internal/modules/cjs/loader.js:961:17) at Function.Module._load (internal/modules/cjs/loader.js:854:27) at Module.require (internal/modules/cjs/loader.js:1023:19) at require (internal/modules/cjs/helpers.js:72:18) at Object. (C:\Users\Kukka\Downloads\sateenkaari\index.js:34:24) at Module._compile (internal/modules/cjs/loader.js:1128:30) at Object.Module._extensions..js (internal/modules/cjs/loader.js:1167:10) at Module.load (internal/modules/cjs/loader.js:983:32) at Function.Module._load (internal/modules/cjs/loader.js:891:14) at Function.executeUserEntryPoint as runMain { code: 'MODULE_NOT_FOUND', requireStack: [ 'C:\Users\me\Downloads\sateenkaari\index.js' ] }

any suggestions?

 

Did you place it in the root of the project? (same place as index.js)

 

If you mean dragging the config.json into the index.js file, it wont allow. If you mean placing the config.json into the sateenkaari folder (the folder where all of the package.json files etc. are, then I did that.

I think you are trying to import it in a wrong way, in your index.js file did you try to require("../../config.json")?

It should be only "config.json" if so

internal/modules/cjs/loader.js:305
throw err;
^

Error: Cannot find module 'C:\Users\Truong Anh\Desktop\bot1\index.js'. Please verify that the package.json has
a valid "main" entry
?[90m at tryPackage (internal/modules/cjs/loader.js:297:19)?[39m
?[90m at Function.Module._findPath (internal/modules/cjs/loader.js:528:18)?[39m
?[90m at Function.Module._resolveFilename (internal/modules/cjs/loader.js:784:27)?[39m
?[90m at Function.Module._load (internal/modules/cjs/loader.js:690:27)?[39m
?[90m at Function.Module.runMain (internal/modules/cjs/loader.js:1047:10)?[39m
?[90m at internal/main/run_main_module.js:17:11?[39m {
code: ?[32m'MODULE_NOT_FOUND'?[39m,
path: ?[32m'C:\Users\Truong Anh\Desktop\bot1\package.json'?[39m,
requestPath: ?[32m'C:\Users\Truong Anh\Desktop\bot1'?[39m
}

this is my trouble error
any suggestions to help me?

Um do you have a package.json file?
If you cloned mine just run npm install

Seems like the problem doesn't occur anymore. Now it has to display an error like this one:

Structures.extend('Guild', Guild => {
^

TypeError: Cannot read property 'extend' of undefined
at Object. (C:\Users\me\Downloads\sateenkaari\index.js:6:12)
[90m at Module._compile (internal/modules/cjs/loader.js:1128:30)[39m
[90m at Object.Module._extensions..js (internal/modules/cjs/loader.js:1167:10)[39m
[90m at Module.load (internal/modules/cjs/loader.js:983:32)[39m
[90m at Function.Module._load (internal/modules/cjs/loader.js:891:14)[39m
[90m at Function.executeUserEntryPoint as runMain[39m
[90m at internal/main/run_main_module.js:17:47[39m

you probably did not install discord.js master, hit

npm i discordjs/discord.js

 

music won't open and this is the error

Error: Error: Cannot find module '@discordjs/opus'
Require stack:

  • C:\Users\Davi\Desktop\Master-Bot-master\node_modules\prism-media\src\util\loader.js
  • C:\Users\Davi\Desktop\Master-Bot-master\node_modules\prism-media\src\opus\Opus.js
  • C:\Users\Davi\Desktop\Master-Bot-master\node_modules\prism-media\src\opus\index.js
  • C:\Users\Davi\Desktop\Master-Bot-master\node_modules\prism-media\src\index.js
  • C:\Users\Davi\Desktop\Master-Bot-master\node_modules\discord.js\src\client\voice\player\BasePlayer.js
  • C:\Users\Davi\Desktop\Master-Bot-master\node_modules\discord.js\src\client\voice\player\BroadcastAudioPlayer.js
  • C:\Users\Davi\Desktop\Master-Bot-master\node_modules\discord.js\src\client\voice\VoiceBroadcast.js
  • C:\Users\Davi\Desktop\Master-Bot-master\node_modules\discord.js\src\client\voice\ClientVoiceManager.js
  • C:\Users\Davi\Desktop\Master-Bot-master\node_modules\discord.js\src\client\Client.js
  • C:\Users\Davi\Desktop\Master-Bot-master\node_modules\discord.js\src\index.js
  • C:\Users\Davi\Desktop\Master-Bot-master\node_modules\discord.js-commando\src\client.js
  • C:\Users\Davi\Desktop\Master-Bot-master\node_modules\discord.js-commando\src\index.js
  • C:\Users\Davi\Desktop\Master-Bot-master\index.js Error: Cannot find module 'node-opus' Require stack:
  • C:\Users\Davi\Desktop\Master-Bot-master\node_modules\prism-media\src\util\loader.js
  • C:\Users\Davi\Desktop\Master-Bot-master\node_modules\prism-media\src\opus\Opus.js
  • C:\Users\Davi\Desktop\Master-Bot-master\node_modules\prism-media\src\opus\index.js
  • C:\Users\Davi\Desktop\Master-Bot-master\node_modules\prism-media\src\index.js
  • C:\Users\Davi\Desktop\Master-Bot-master\node_modules\discord.js\src\client\voice\player\BasePlayer.js
  • C:\Users\Davi\Desktop\Master-Bot-master\node_modules\discord.js\src\client\voice\player\BroadcastAudioPlayer.js
  • C:\Users\Davi\Desktop\Master-Bot-master\node_modules\discord.js\src\client\voice\VoiceBroadcast.js
  • C:\Users\Davi\Desktop\Master-Bot-master\node_modules\discord.js\src\client\voice\ClientVoiceManager.js
  • C:\Users\Davi\Desktop\Master-Bot-master\node_modules\discord.js\src\client\Client.js
  • C:\Users\Davi\Desktop\Master-Bot-master\node_modules\discord.js\src\index.js
  • C:\Users\Davi\Desktop\Master-Bot-master\node_modules\discord.js-commando\src\client.js
  • C:\Users\Davi\Desktop\Master-Bot-master\node_modules\discord.js-commando\src\index.js
  • C:\Users\Davi\Desktop\Master-Bot-master\index.js Error: Cannot find module 'opusscript' Require stack:
  • C:\Users\Davi\Desktop\Master-Bot-master\node_modules\prism-media\src\util\loader.js
  • C:\Users\Davi\Desktop\Master-Bot-master\node_modules\prism-media\src\opus\Opus.js
  • C:\Users\Davi\Desktop\Master-Bot-master\node_modules\prism-media\src\opus\index.js
  • C:\Users\Davi\Desktop\Master-Bot-master\node_modules\prism-media\src\index.js
  • C:\Users\Davi\Desktop\Master-Bot-master\node_modules\discord.js\src\client\voice\player\BasePlayer.js
  • C:\Users\Davi\Desktop\Master-Bot-master\node_modules\discord.js\src\client\voice\player\BroadcastAudioPlayer.js
  • C:\Users\Davi\Desktop\Master-Bot-master\node_modules\discord.js\src\client\voice\VoiceBroadcast.js
  • C:\Users\Davi\Desktop\Master-Bot-master\node_modules\discord.js\src\client\voice\ClientVoiceManager.js
  • C:\Users\Davi\Desktop\Master-Bot-master\node_modules\discord.js\src\client\Client.js
  • C:\Users\Davi\Desktop\Master-Bot-master\node_modules\discord.js\src\index.js
  • C:\Users\Davi\Desktop\Master-Bot-master\node_modules\discord.js-commando\src\client.js
  • C:\Users\Davi\Desktop\Master-Bot-master\node_modules\discord.js-commando\src\index.js
  • C:\Users\Davi\Desktop\Master-Bot-master\index.js at Object.loader as require at loadOpus (C:\Users\Davi\Desktop\Master-Bot-master\node_modules\prism-media\src\opus\Opus.js:17:17) at new OpusStream (C:\Users\Davi\Desktop\Master-Bot-master\node_modules\prism-media\src\opus\Opus.js:46:10) at new Encoder (C:\Users\Davi\Desktop\Master-Bot-master\node_modules\prism-media\src\opus\Opus.js:135:5) at AudioPlayer.playPCMStream (C:\Users\Davi\Desktop\Master-Bot-master\node_modules\discord.js\src\client\voice\player\BasePlayer.js:58:34) at AudioPlayer.playUnknown (C:\Users\Davi\Desktop\Master-Bot-master\node_modules\discord.js\src\client\voice\player\BasePlayer.js:53:17) at VoiceConnection.play (C:\Users\Davi\Desktop\Master-Bot-master\node_modules\discord.js\src\client\voice\util\PlayInterface.js:71:28) at C:\Users\Davi\Desktop\Master-Bot-master\commands\music\play.js:228:12 at processTicksAndRejections (internal/process/task_queues.js:88:5)