Music Bot for Discord using DSharpPlus, Lavalink4NET and Lavalink
- .NET 8.0 runtime
- JDK 17.0.2
- Lavalink 4.0.8
- To set up Lavalink, follow the instructions from the official Lavalink website.
- Go to the Discord Developer page and create a new app. Go to the Bot tab and press Reset Token button. Press the Copy button and save the token for later.
- Download the contents of this repository.
- Rename example.appsettings.json to appsettings.json and paste your discord token into the token field. Configure the remaining fields in the appsettiings.json file. Their values should be in the corresponding fields in the Lavalink configuration file.
- Build Bot application using Visual Studio or Command Prompt.
- Run Lavalink.
- Run the Bot application.
To invite bot go to the Discord Developer page, select your bot and go to the OAuth2 tab. Scroll down and check the applications.commands and bot checkboxes. Bot permissions should have appeard. Check Read Messages/View Channels, Send Messages, Manage Messages, Embed Links, Read Message History, Add Reactions, Connect and Speak permissons checkboxes. Copy generated URL and paste it into your browser. Choose server and click Authorize button.
An example application.yml file can be found at this link. You can also copy my application.yml options. Remember to change the port, address and password to match the values in the appsettings.json file.
Important
Now you will most likely have to use OAuth Tokens to make the bot work. With the updated contents of the application.yml file below, you should be asked by Lavalink to give youtube-source access to your account at Lavalink startup. Correct authorization should result in your token being displayed in a terminal running Lavalink. You can copy the obtained token into the application.yml file as the value of the "refreshToken" key and uncomment it by removing the "#" symbol. Using your main account for authorization is not recommended. For more information visit link.
server:
port: 2333
address: 0.0.0.0
http2:
enabled: false
plugins:
youtube:
enabled: true
allowSearch: true
allowDirectVideoIds: true
allowDirectPlaylistIds: true
clients:
- MUSIC
- ANDROID_VR
- TVHTML5EMBEDDED
oauth:
enabled: true
# refreshToken: "your token"
lavalink:
plugins:
- dependency: "dev.lavalink.youtube:youtube-plugin:1.12.0"
snapshot: false
server:
password: "youshallnotpass"
sources:
youtube: false
bandcamp: false
soundcloud: false
twitch: false
vimeo: false
nico: false
http: false
local: false
filters:
volume: true
equalizer: true
karaoke: true
timescale: true
tremolo: true
vibrato: true
distortion: true
rotation: true
channelMix: true
lowPass: true
bufferDurationMs: 1200
frameBufferDurationMs: 10000
opusEncodingQuality: 8
resamplingQuality: LOW
trackStuckThresholdMs: 10000
useSeekGhosting: true
youtubePlaylistLoadLimit: 6
playerUpdateInterval: 5
youtubeSearchEnabled: true
soundcloudSearchEnabled: true
gc-warnings: true
metrics:
prometheus:
enabled: false
endpoint: /metrics
sentry:
dsn: ""
environment: ""
logging:
file:
path: ./logs/
level:
root: INFO
lavalink: INFO
dev.lavalink.youtube.http.YoutubeOauth2Handler: INFO
request:
enabled: true
includeClientInfo: true
includeHeaders: false
includeQueryString: true
includePayload: true
maxPayloadLength: 10000
logback:
rollingpolicy:
max-file-size: 1GB
max-history: 30