Giter Site home page Giter Site logo

music_bot's Introduction

Music bot

Since a lot of discord music bots are being blocked by youtube nowadays I've decided to write up a quick project that will allow anyone to host their own discord bot. This bot includes the following commands:

/help - displays all the available commands /p - finds the song on youtube and plays it in your current channel. Will resume playing the current song if it was paused
/q - displays the current music queue
/skip - skips the current song being played
/clear - Stops the music and clears the queue
/leave - Disconnected the bot from the voice channel
/pause - pauses the current song being played or resumes if already paused
/resume - resumes playing the current song

Running with docker

To run with docker simply run the command docker run -e TOKEN=<your_token_here> -d pabolo02345/music_bot:latest

Installation

To run the discord bot all you need is python 3.4 or above.
Then run pip install -r requirements.txt to install all of the python dependencies.
Please note that you will also need to have ffmpeg installed and make sure that the path to the bin folder is in your environment variables.

Creating a bot

To create a bot follow my tutorial on https://www.youtube.com/watch?v=PJDuI9n7rWE&t=325s&ab_channel=Computeshorts. This will guide on how to create a bot.

Deploying your bot

Lastly you'll need to deploy your bot. You can follow my other tutorial on deploying with docker https://www.youtube.com/watch?v=z58g7_dHeMA but the gist is to have a server setup with all the dependencies and then run python main.py.

Token

Remember that you need to have your token setup in your environment variables as well and it should be under TOKEN. On windows you can do this by running SET TOKEN=<you_token_here>

music_bot's People

Contributors

ignacioromang avatar pawel02 avatar shaxi1 avatar thestef56 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

music_bot's Issues

Issue On music_cog.py

File "f:\music_bot-main\main.py", line 7, in
from music_cog import music_cog
File "f:\music_bot-main\music_cog.py", line 95
self.is_playing = False
TabError: inconsistent use of tabs and spaces in indentation

How can i fix that?

Hello, I started getting an error.

I have changed code a little bit for me but it didn't affect the code much and its worked for about a month then i started getting an error.
RuntimeWarning: Enable tracemalloc to get the object allocation traceback
[download] Downloading playlist: levan polka
[youtube:search] query "levan polka": Downloading page 1
[youtube:search] playlist levan polka: Downloading 1 videos
[download] Downloading video 1 of 1
[youtube] S4nwKLxEboo: Downloading webpage
[youtube] Downloading just video S4nwKLxEboo because of --no-playlist
[download] Finished downloading playlist: levan polka
Ignoring exception in command myus:
Traceback (most recent call last):
File "C:\Users\User\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\discord\ext\commands\core.py", line 85, in wrapped
ret = await coro(*args, **kwargs)
File "C:\Users\User\Desktop\JavaH\music_cog.py", line 136, in skip
await self.play_music(ctx)
File "C:\Users\User\Desktop\JavaH\music_cog.py", line 67, in play_music
self.vc.play(discord.FFmpegPCMAudio(m_url, **self.FFMPEG_OPTIONS), after=lambda e: self.play_next())
File "C:\Users\User\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\discord\player.py", line 225, in init
super().init(source, executable=executable, args=args, **subprocess_kwargs)
File "C:\Users\User\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\discord\player.py", line 138, in init
self._process = self._spawn_process(args, **kwargs)
File "C:\Users\User\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\discord\player.py", line 147, in _spawn_process
raise ClientException(executable + ' was not found.') from None
discord.errors.ClientException: ffmpeg was not found.

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "C:\Users\User\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\discord\ext\commands\bot.py", line 939, in invoke
await ctx.command.invoke(ctx)
File "C:\Users\User\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\discord\ext\commands\core.py", line 863, in invoke
await injected(*ctx.args, **ctx.kwargs)
File "C:\Users\User\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\discord\ext\commands\core.py", line 94, in wrapped
raise CommandInvokeError(exc) from exc
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: ClientException: ffmpeg was not found.

When the bot starts it "Spamms" in all text channels

When the bot starts it "Spamms" in all text channels with the commands that can be used.
Do to it being Discord administrator.

A solution could be to change the bots requirements to be [Use application commands]
or something like that

It's not launching.

PS C:\Users\danie\Desktop\Xasion's Music Bot\discord bot> python main.py
Traceback (most recent call last):
File "C:\Users\danie\Desktop\Xasion's Music Bot\discord bot\main.py", line 19, in
bot.run(os.getenv("TOKEN"))
File "C:\Users\danie\AppData\Local\Programs\Python\Python310\lib\site-packages\discord\client.py", line 723, in run
return future.result()
File "C:\Users\danie\AppData\Local\Programs\Python\Python310\lib\site-packages\discord\client.py", line 702, in runner
await self.start(*args, **kwargs)
File "C:\Users\danie\AppData\Local\Programs\Python\Python310\lib\site-packages\discord\client.py", line 665, in start
await self.login(*args, bot=bot)
File "C:\Users\danie\AppData\Local\Programs\Python\Python310\lib\site-packages\discord\client.py", line 511, in login
await self.http.static_login(token.strip(), bot=bot)
AttributeError: 'NoneType' object has no attribute 'strip'

What do i do?

missing 1 required keyword-only argument: 'intents'

I tried to run my code but this error comes up

Traceback (most recent call last):
File "C:\Users\Tom\Downloads\music_bot-main\main.py", line 9, in
bot = commands.Bot(command_prefix='/')
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: BotBase.init() missing 1 required keyword-only argument: 'intents'

Indentation Error

Hi,

I wanted to build this app as Docker Image and I got this error

2023-03-10 02:18:27 Traceback (most recent call last):
2023-03-10 02:18:27   File "main.py", line 7, in <module>
2023-03-10 02:18:27     from music_cog import music_cog
2023-03-10 02:18:27   File "/app/music_cog.py", line 95
2023-03-10 02:18:27     self.is_playing=False
2023-03-10 02:18:27                         ^
2023-03-10 02:18:27 TabError: inconsistent use of tabs and spaces in indentation

I used to create my docker image " docker build -t discordmusic . "

No errors but music do not play

So i ported bot to py-cord and added slash command support. Everything works i got no errors doing /play. Bot joins channel and just sit there mutted. On console i can see dowload from youtube_dl finished succesfuly. I have ffmpeg setted in system variables.

Ps any idea how to get rid of old music trakcs so it dont stack and fill drive ?

Bot not responding to my commands

I started the bot, but none of the commands are recognized, throwing this messages in the console.

C:\Users\roman\Desktop\music_bot-main\main.py:15: RuntimeWarning: coroutine 'BotBase.add_cog' was never awaited
  bot.add_cog(help_cog(bot))
RuntimeWarning: Enable tracemalloc to get the object allocation traceback
C:\Users\roman\Desktop\music_bot-main\main.py:16: RuntimeWarning: coroutine 'BotBase.add_cog' was never awaited
  bot.add_cog(music_cog(bot))
RuntimeWarning: Enable tracemalloc to get the object allocation traceback
[2023-02-08 02:43:21] [INFO    ] discord.client: logging in using static token
[2023-02-08 02:43:22] [INFO    ] discord.gateway: Shard ID None has connected to Gateway (Session ID: 7c8c0489dbc8e8c9bffdd65f1b5b4a68).
[2023-02-08 02:43:26] [ERROR   ] discord.ext.commands.bot: Ignoring exception in command None
discord.ext.commands.errors.CommandNotFound: Command "help" is not found

Bot won't start.

C:\Users\BaraK\Desktop\FadertyBot\venv\Scripts\python.exe C:\Users\BaraK\Desktop\FadertyBot\main.py

Process finished with exit code 0

using in multiple servers

how can i use this bot in multiple channels with different servers?
bot cant join different voice channels when connect to a voice channel and play music.

Issue with music_cog

File "d:\Bot\music_bot\main.py", line 4, in
from music_cog import music_cog
ModuleNotFoundError: No module named 'music_cog'

How can i fix this issue??

Play function prevents playback

There's an issue which prevents bot from playing.

In play_music function there is a self.music_queue.pop(0) statement commented as

#remove the first element as you are currently playing it

But if there is only one song in the queue, which is the first one added, the queue is empty after removing it from the queue, which causes the called play_next function not to run because it has an if statement that disables playback when the queue is empty. Thus, the music doesn't even start playing.

def play_next(self): if len(self.music_queue) > 0:

Error on any command

ERROR discord.ext.commands.bot Ignoring exception in command None
discord.ext.commands.errors.CommandNotFound: Command "play" is not found

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.