Learn to Code via Tutorials on Repl.it!

← Back to all posts
OPUS SUPPORT FOR DISCORD MUSIC BOTS!
h
Scoder12

UPDATE: Repl.it has Native OPUS and Discord Music Bot support so you don't need to use this post anymore

The wait is over! You can now make music bots with discord! I have compiled libopus.so for repl.it which you can now use to make music bots.

To make your bot in python, all you have to do is fork the repl linked below.
If you want to use a different language than python for your bot, you need to download the .so file. Just fork the repl, press ctrl+shift+s, type php -S 0.0.0.0:8080, and then add /libopus.so.0.8.0 to the url of your repl to download the file. Next, upload this file into your repl.

Ask questions in the comments, I might be able to help.

Before you comment asking for help:

Try it first, then let me know whether it worked or not. If it worked for you I'll update the post, otherwise I'll help the best I can.

Enjoy, upvote if it helped you!

Voters
sbadijbajsbdasd
pgramadordoges
Lakao457
RamziMuderisMud
elod
MichaRyz
Usermc
Hodat2k9
JoshuaGottfried
MGPlayzYT
Comments
hotnewtop
amasad

Thanks so much, Scoder! I will close the bug report and direct people to this.

EDIT: we just fixed this for Node.js. Try it out.

tpunn19

@amasad, This only works on Python. Most people who make Discord bots won't be able to use this feature.

OctagonalT

@tpunn19 yea im using js

amasad

@OctagonalT @tpunn19 hey can you send a repl where this fails so I can debug and fix?

OctagonalT

@amasad theres no bug its legit missing ffmpeg

amasad

@OctagonalT it turned out we blocked UDP ports. I just made an exception to discord. Tried it out.

tpunn19

@amasad Thank you! It works now without Scoder12's solution. I can just install the requirements from NPM and it works.

amasad

@tpunn19 Awesome! I need help adding a node.js template to our template library -- do you have a simple node.js music bot repl we can add?

https://repl.it/talk/announcements/Discord-Music-Bots-Native-Support/50173

tpunn19

@amasad I only have this so far: https://repl.it/@tpunn19/Discordjs-Music-Bot. It only connects to a voice channel and plays some music, nothing special. I added the same markdown you did for Python except with the JS instructions.

FalcoPheonixYT

Hey pls help i am using NODE.JS. When i give the command to play it just doesnt do anything only when i do !play it connects, but when i do !play(url) nothing happens pls help me thanks !!

PterTill

It's a virus guys, DO NOT INSTALL/DOWNLOAD IT!!!!!!

Scoder12

@PterTill what do you mean? This is not a virus.

PterTill

@Scoder12 See inside the scripts. There are random characters

Scoder12

@PterTill that is how .so files work. They are compiled binaries in the ELF format.

Chirpi

what command do i type in discord for it to play music

Mckael123

add /libopus.so.0.8.0 to the url of your repl to download the file. Next, upload this file into your repl.

how to do that in repl ? in shell?

Scoder12

@Mckael123 This post isn't necessary anymore, repl.it supports this

Mckael123

@Scoder12 but sir how tell me

TayyabSheikh

where should i write the bot token

Scoder12
TayyabSheikh

hey how do you link the bot to the code. I also wonder how the music is imported

mwit308

Well, it works. But sometimes it has a problem.
"RuntimeError: PyNaCl library needed in order to use voice"
It comes and goes for no reasons, Any idea?

Scoder12

@mwit308 in the terminal type poetry add pynacl

mwit308

@Scoder12 I used to do it, and it just reports some error.
I don't remember it, since I stop that project and not recompile after the success. But thanks anyway.

TroolProo

Hello I have an error in my music bot that does not play the songs, I did it from my pc, I uploaded it and it does not play, but if I open it from visual studio code it plays, I wanted to see if someone can help me I am new to this world of programming

amasad

@TroolProo it turned out we blocked UDP ports. I just made an exception to discord. Try it out and let me know if it works.

TroolProo

@amasad Thank you very much, I will try it and let you know

Hodat2k9

When I add discord.opus.load_opus("./libopus.so.0.8.0"), it stops working. It has a lot of errors, but when I scroll down it said files such as in directory.

Scoder12

@Hodat2k9 fork the repl I attached first so you have that file, or upload it into your repl

CoolJames1610

I followed a tutorial and I think thats the problem. How would I use opus to create a music bot?

tpunn19

Hi, my entire bot is written in JavaScript, so I would like to continue using Discord.js instead of Discord.py. I don't seem to understand based on your article on how to add OPUS. If there is no way, then I will write my next bot in Python (though I prefer JavaScript).

tpunn19

I tried doing it, and it says: [VOICE_CONNECTION_TIMEOUT]: Connection not established within 15 seconds.

Scoder12

@tpunn19 I'm trying to get this to work and I will let you know if I can figure it out.

tpunn19

@Scoder12, Thank you so much!

tpunn19

@Scoder12 Did you get anything yet? Just checking.

Scoder12

@tpunn19 havent been working on it at all

amasad

@tpunn19 Hey I just put out a potential fix. Let me know if it works for you now.

TrainsRUs

Still not working for me - The code hangs on await message.author.voice.channel.connect() and never completes. The bot physically joins the channel but any attempt to disconnect or play audio, it just Not connected to voice.

Scoder12

@TrainsRUs I got the same issue and have opened an issue in discord.py for it.

TrainsRUs

@Scoder12 Yeah I think its a repl issue still - copied the code onto my windows PC and it works a dream (without the problem mentioned above). Have to keep that part of my bot locally hosted now though :(.

Scoder12

@TrainsRUs should work now! It was a repl.it issue!

TrainsRUs

@Scoder12 Thanks, I'll give it a try and report back!

TrainsRUs

@Scoder12 IT WORKS!!!!!
Thank you so much!

TrainsRUs

@Scoder12 Audio quality on the free service is certainly limited though

Mckael123

@TrainsRUs teach me man

TrainsRUs

@Mckael123 how to create a discord bot or how to just use music?

Mckael123

@TrainsRUs how to create discord bot can play music

TrainsRUs

@Mckael123 well here's the official quick-start guide for general python bots:
discord.py package required
https://discordpy.readthedocs.io/en/latest/quickstart.html
and here's the api reference for adding stuff etc:
https://discordpy.readthedocs.io/en/latest/api.html
(although stackoverflow might be more helpful ;) )

Since you want to do music, you need to look into ffmpeg.
Also you need to have the discord.py[voice] package installed to effectively connect to vc and play audio.

After that you're going to need to think about audio playlists etc.. This is relatively simplified if you use an array or dictionaries which store your next track, and recursive functions.

Trunks8257

Hi, I'm actually doing this in nodejs and I'm getting the same as before the file was added (the bot joins the vc but doesn't play nothing). I'm using Discord.js 12.2.0 and ffmpeg-static.

Trunks8257

idk if it could be useful but I get an error

[VOICE_CONNECTION_TIMEOUT]: Connection not established within 15 seconds.

Scoder12

@Trunks8257 I don't know whether it works on discord.js.

Trunks8257

@Scoder12
Ok,no problem. Do you know any way of doing it in discord.js?

amasad

@Trunks8257 it turned out we blocked UDP ports. I just made an exception to discord. Try it out and let me know if it works.

FalcoPheonixYT

@Trunks8257 Same is happening with me still this issue is not resolved

xxpertHacker

I can't believe the Repl.it team gave up and didn't actually implement this themselves. Good work nonetheless.

mat1

@StudentFires replit in a nutshell

xxpertHacker

@mat1 Then why can't we make out own Repls? Check my bio.

[deleted]

@mat1 yes they need to hire more staff ffs and actually implement this sh*t

amasad
amasad

@willuhmjs We're hiring as fast as we can. Please ask your friends to apply: https://repl.it/jobs

xxpertHacker

@amasad Oh ha, I never actually cared, but still cool.

[deleted]

Can we get more in depth instructions for nodejs installation

Scoder12

@willuhmjs what are you having trouble with

SilentShadowBla

yes that would be helpful xd @willuhmjs

SilentShadowBla

can u give me an overall way to do this in discord.js?^_^ @Scoder12

Scoder12

@SilentShadowBla try it first, then let me know whether it worked or not. If it worked for you I'll update the post, otherwise I'll help the best I can.

SilentShadowBla

so i have the file in my nodejs repl, but how do I use it? (I'm retarded)

@Scoder12

Scoder12

@SilentShadowBla try running some voice code. Let me know what happens.

SilentShadowBla

how? xd @Scoder12

Scoder12

@SilentShadowBla if you're not running a music bot you have no reason to use this post. Let me know if you actually run any code and need help.

amasad

@willuhmjs it turned out we blocked UDP ports. I just made an exception to discord. Try it out and let me know if it works.

a5rocks

Have a virtual cookie! By the way, to start a local web server you can also do python3 -m http.server 8080 (if you want to stay in the python ecosystem :p)

Scoder12

@a5rocks yeah, I never remember that command haha! Luckily its repl.it so everything is already installed.

Cookiezz

@a5rocks yus! COOKIEZZ

Codemonkey51

YAY