Code Monkey home page Code Monkey logo

darkempire78 / music-discord-bot Goto Github PK

View Code? Open in Web Editor NEW
87.0 3.0 51.0 961 KB

A music Discord bot with more than 30+ commands which allows to play music on your server efficiently. Supports Youtube, Spotify, Deezer and Soundcloud links. Skips intros and blanks in the music with Sponsorblock.

Home Page: https://top.gg/bot/796749718217555978

License: GNU General Public License v3.0

Python 99.31% Dockerfile 0.69%
discord discord-bot discord-py discordbot discord-music-bot music-bot-discord discord-bot-music music deezer soundcloud

music-discord-bot's Introduction

Music Discord Bot

A Discord bot with more than 30+ commands which allows to play music on your server efficiently. Supports Youtube, Spotify, Deezer and Soundcloud links. Skips intros and blanks in the music with Sponsorblock (optional).

Installation

  • create a discord application / bot here
  • Install all dependencies : pip install -r requirements.txt.
  • Download Lavalink.
  • Install Java 11+
  • Create a MySQL database and use the Scripts/generateDatabase.sql file to create the table.
  • Edit configuration example.json :
{
    "token": "", // Your bot token
    "prefix": "?", // Your prefix
    
    "playlistLimit": "15", // Optional - Defaults to 15 if not provided 0 is unlimited
    "sponsorblock": true, // True if you want to skip intros and blanks in the music

    // Spotify => https://developer.spotify.com/dashboard/ 
    "spotifyClientId": "", // Your Spotify ID (OPTIONAL : Spotify links support)
    "spotifyClientSecret": "", // Your Spotify secret (OPTIONAL : Spotify links support)
    
    "MySQLHost": "", // Your MySQL host
    "MySQLLogin": "", // Your MySQL login
    "MySQLPasword": "", // Your MySQL password
    "MySQLDatabase": "" // Your MySQL database
}
  • Rename it to configuration.json.
  • Edit emojis.json

Finally, host the bot and invite it to your own server.

Run the bot

  • Run Lavalink.jar (from Lavalink) with java -jar Lavalink.jar
    • Note: you will likely want to use a config file in the same directory as Lavalink.jar to control its settings
  • Run the bot python3 main.py

Run in docker

  • skip all but the first installation steps above
  • install docker
  • install docker-compose
  • copy the configuration.docker.json file to ./configuration.json
  • fill in your discord bot token
    • optionally the spotify client id/secret && dbl tokens
  • run docker-compose build
  • run docker-compose up -d db
  • run docker-compose up -d

Note: In theory you can skip docker-compose up -d db and just run docker-compose up -d but the timing of the db startup and running of the generateDatabase.sql on initial startup can sometimes cause the music bot to fail to start so its best to just start the db first to give it enough time

Docker running / debugging tips

  • you can run docker-compose logs to view logs for all services
  • you can run docker-compose logs <service> eg: docker-compose logs musicbot to see the logs for a specific service (look in the compose file for the service names)
  • you can run docker-compose stop to stop the music bot / db / lavalink containers
  • you can run docker-compose start to start the music bot / db / lavalink after stopping

Features

  • Play music from YouTube
  • Support links from YouTube, Spotify, Deezer and Soudcloud
  • Support YouTube lives
  • Support playlists from Spotify, Deezer, Soundcloud and YouTube
  • Playlist system
  • Sponsorblock integration to skip intros and blanks in the music
  • Many commands
  • Complex queue commands

Preview

Commands

?play <Url/Query> : Search on youtube and play the music.
?search <Query> : Search a song on youtube.
?nowplaying : Display data about the current song.
?join : Add the bot to your voice channel.
?leave : Remove the bot of your voice channel.
?pause : Pause the current song.
?resume : Resume the current song.
?volume <0-100> : Change the bot's volume.
?queue : Display the queue.
?shuffle : Shuffle the queue.
?move <IndexFrom> <IndexTo> : Move a song in the queue.
?remove <Index> : Remove the song with its index.
?removedupes : Remove all duplicates song from the queue.
?leavecleanup : Remove absent user's songs from the queue.
?clear : Clear the queue.
?replay : Replay the current song.
?reload : Reload the current song.
?loop : Enable or disable the loop mode.
?loopqueue : Enable or disable the loop queue mode.

?playlist add <Url> : Add a track to your playlist.
?playlist remove <Index> : Remove a track to your playlist.
?playlist display : Display playlist's songs.
?playlist load : Add the whole playlist to the queue.

?stats : Display the bot's stats.
?support : Give a link to join the support server.
?invite : Give a link to invite the bot.
?vote : Give the Top.gg link to vote for the bot.
?help : Display the help.

?logout : Stop the bot process.

Discord Bots

Soon

Project : https://github.com/Darkempire78/Music-Discord-Bot/projects/2

Discord

Join the Discord server !

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

License

This project is under GPLv3.

Advice :

You should use Discord Tools to code your Discord bots on Visual Studio Code easier. Works for Python (Discord.py), Javascript (Discord.js) and Java (JDA). Generate template bot and code (snippets).

music-discord-bot's People

Contributors

darkempire78 avatar listba avatar toby406 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  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

music-discord-bot's Issues

While using Move Command raised an exception: AttributeError: 'tuple' object has no attribute 'title' and 'url'

Command raised an exception: AttributeError: 'tuple' object has no attribute 'title'
and
Command raised an exception: AttributeError: 'tuple' object has no attribute 'title'

The problem is
Cogs/move.py

embed = discord.Embed(title="Song moved", description=f"- [**{trackToMove.title}**]({trackToMove.uri}) was moved from `{indexFromFake}` to `{indexToFake}`.",

here trackToMove is a tuple inside a list,
so better use trackToMove[index_number_of_title] and trackToMove[index_number_of_url]

so solve is

embed = discord.Embed(title="Song moved", description=f"- [**{trackToMove[5]}**]({trackToMove[4]}) was moved from `{indexFromFake}` to `{indexToFake}`.",

Age restriction

Hello, i have a issue with play music with an age restriction.

While using remove Command raised an exception: AttributeError: 'Bot' object has no attribute 'music'

Problem while trying to remove a song from the queue it shows that error
the problem is in
Cogs/removeRemoverange.py

if (int(index) - 1) > len(self.bot.music[ctx.guild.id]["musics"]): return await ctx.channel.send(f"{self.bot.emojiList.false} {ctx.author.mention} The index is invalid!")

Solve,

just comment out these 2 line no need for any use.

after commenting it out it will show another error,

Command raised an exception: IndexError: list index out of range

because
track = tracks[index]

solve is

track = tracks[index-2]

Use StreamURLFetcher & PyTube instead of youtube_dl

Hi there!

I recently saw this project from you.
I'm maintainer of youtube-search-python & I made few additions to my project which you might like.

As you might be aware, that youtube_dl or vanilla PyTube is kinda slow to get video URLs as they make "additional web requests" for getting the exact same response which you already have when displaying it to the user.

from youtubesearchpython import *
fetcher = StreamURLFetcher() # Instantiate this class only once (makes web requests).

video = Video.get("https://www.youtube.com/watch?v=aqz-KE-bpKQ") # Let's assume you get information of this video for displaying.
url = fetcher.get(video, 251) # You can use same response to get its stream URL (Very fast, does not make any requests).
print(url)

See more here.

Thankyou, I just wanted to let you know.

NOTE: I'm not sure how stable it is at the moment, but is definitely worth trying.
You may close (or delete) this issue, once you read.

mysql.connector

Refuse to import the module mysql
ModuleNotFoundError: No module named 'mysql'

Missing from requirements.txt + playlist limits

Hi
After some time managed to run it, well there are some glitches with music,
i don't know if it's because Lavalink, but i see its resource usage is minimal yet
periodically stutters, what's worse is sometimes then speeds up to match timestamp,
occasionally quality drops, so many problems, maybe its Discord? I'm new to all this.
I think these are missing from requirements.txt
wavelink
youtube-search-python
psutil
Also the 15 limit for playlist is absurd, queues too, either remove or raise.
Also the shuffle isn't working as advertised :) but i see you have task for that.
Thanks

KeyError

Hello, today i tried to setup this musicbot. everything worked fine, i added my spotify ClientID, ClientSecret & my Discordtoken into the configfile. however now if i try to run it it print out a error that i cant fix my myself. Here is the error written in text:

D:\Downloads\downloaded_pythonprojects\Music-Discord-Bot-main>main.py
Traceback (most recent call last):
  File "D:\Downloads\downloaded_pythonprojects\Music-Discord-Bot-main\main.py", line 72, in <module>
    spotifyAppToken = tekore.request_client_token(spotifyClientId, spotifyClientSecret)
  File "D:\python\lib\site-packages\tekore\_auth\util.py", line 204, in request_client_token
    return cred.request_client_token()
  File "D:\python\lib\site-packages\tekore\_auth\refreshing.py", line 148, in request_client_token
    token = self._client.request_client_token()
  File "D:\python\lib\site-packages\tekore\_sender\client.py", line 79, in wrapper
    return post_func(request, response, *params)
  File "D:\python\lib\site-packages\tekore\_auth\expiring\decor.py", line 30, in func
    return Token(response.content, uses_pkce)
  File "D:\python\lib\site-packages\tekore\_auth\expiring\token.py", line 39, in __init__
    self._scope = Scope(*token_info['scope'].split(' '))
KeyError: 'scope'

and here a screenshot:
image

Command raised an exception: ZeroConnectedNodes:

Its return a error in Discord Channel when i put any Yt,Spotify or other link on my command Play.

[Command raised an exception: ZeroConnectedNodes: ]

WEBSOCKET | Connection Failure::
Traceback (most recent call last):
File "C:\Users\elemesmo\anaconda3\lib\site-packages\wavelink\websocket.py", line 76, in _connect
self._websocket = await self._node.session.ws_connect(uri, headers=self.headers, heartbeat=self._node.heartbeat)
File "C:\Users\elemesmo\anaconda3\lib\site-packages\aiohttp\client.py", line 754, in _ws_connect
resp = await self.request(
File "C:\Users\elemesmo\anaconda3\lib\site-packages\aiohttp\client.py", line 544, in _request
await resp.start(conn)
File "C:\Users\elemesmo\anaconda3\lib\site-packages\aiohttp\client_reqrep.py", line 905, in start
self._continue = None
File "C:\Users\elemesmo\anaconda3\lib\site-packages\aiohttp\helpers.py", line 656, in exit
raise asyncio.TimeoutError from None
asyncio.exceptions.TimeoutError

I Have everything running great in MySQL. I think its some problem with youtubedl

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.