Learn to Code via Tutorials on Repl.it!

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

UPDATE: Now Repl.it has Native OPUS and Discord Music Bot support

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!

Commentshotnewtop
amasad (2524)

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 (7)

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

amasad (2524)

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

OctagonalT (5)

@amasad theres no bug its legit missing ffmpeg

amasad (2524)

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

tpunn19 (7)

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

amasad (2524)

@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 (7)

@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.

mwit308 (0)

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 (733)

@mwit308 in the terminal type poetry add pynacl

TroolProo (0)

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 (2524)

@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 (0)

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

Hodat2k9 (0)

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 (733)

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

CoolJames1610 (618)

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

tpunn19 (7)

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 (7)

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

Scoder12 (733)

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

tpunn19 (7)

@Scoder12 Did you get anything yet? Just checking.

Scoder12 (733)

@tpunn19 havent been working on it at all

amasad (2524)

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

TrainsRUs (5)

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 (733)

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

TrainsRUs (5)

@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 (733)

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

TrainsRUs (5)

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

TrainsRUs (5)

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

TrainsRUs (5)

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

Trunks8257 (0)

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 (0)

idk if it could be useful but I get an error

[VOICE_CONNECTION_TIMEOUT]: Connection not established within 15 seconds.

Scoder12 (733)

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

Trunks8257 (0)

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

amasad (2524)

@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.

xxpertHacker (387)

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

xxpertHacker (387)

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

willuhmjs (8)

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

amasad (2524)

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

xxpertHacker (387)

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

willuhmjs (8)

Can we get more in depth instructions for nodejs installation

Scoder12 (733)

@willuhmjs what are you having trouble with

SilentShadowBla (541)

yes that would be helpful xd @willuhmjs

SilentShadowBla (541)

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

Scoder12 (733)

@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 (541)

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

@Scoder12

Scoder12 (733)

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

Scoder12 (733)

@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 (2524)

@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 (793)

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 (733)

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