Discord Cannot Read Property Isforcused of Null
Discord Player
Complete framework to facilitate music commands using discord.js.
Installation
Install discord-player
$ npm install --save discord-player
Install @discordjs/opus
$ npm install --save @discordjs/opus
Install FFmpeg or Avconv
-
Official FFMPEG Website: https://www.ffmpeg.org/download.html
-
Node Module (FFMPEG): https://npmjs.com/parcel/ffmpeg-static
-
Avconv: https://libav.org/download
Features
- Unproblematic & piece of cake to use
🤘 - Beginner friendly
😱 - Sound filters
🎸 - Lightweight
☁️ - Custom extractors support
🌌 - Multiple sources support
✌ - Play in multiple servers at the same time
🚗 - Does not inject anything to discord.js or your discord.js client
💉 - Allows you to accept full control over what is going to be streamed
👑
Documentation
Getting Started
Start of all, yous will demand to register slash commands:
const { Balance } = require ( "@discordjs/residuum" ) ; const { Routes } = crave ( "discord-api-types/v9" ) ; const commands = [ { name: "play" , description: "Plays a song!" , options: [ { name: "query" , blazon: "STRING" , description: "The song you desire to play" , required: truthful } ] } ] ; const rest = new REST ( { version: "9" } ) . setToken ( process . env . DISCORD_TOKEN ) ; ( async ( ) => { try { console . log ( "Started refreshing awarding [/] commands." ) ; expect residuum . put ( Routes . applicationGuildCommands ( CLIENT_ID , GUILD_ID ) , { torso: commands } , ) ; console . log ( "Successfully reloaded application [/] commands." ) ; } catch ( error ) { console . error ( fault ) ; } } ) ( ) ;
Now y'all can implement your bot's logic:
const { Client, Intents } = crave ( "discord.js" ) ; const client = new Discord . Customer ( { intents: [ Intents . FLAGS . GUILDS , Intents . FLAGS . GUILD_MESSAGES , Intents . FLAGS . GUILD_VOICE_STATES ] } ) ; const { Thespian } = crave ( "discord-thespian" ) ; // Create a new Player (you don't need any API Key) const player = new Player ( client ) ; // add the trackStart event so when a vocal will be played this message will be sent player . on ( "trackStart" , ( queue , track ) => queue . metadata . channel . send ( `🎶 | Now playing ** ${ track . championship } **!` ) ) client . once ( "ready" , ( ) => { console . log ( "I'm gear up !" ) ; } ) ; customer . on ( "interactionCreate" , async ( interaction ) => { if ( ! interaction . isCommand ( ) ) return ; // /play track:Despacito // will play "Despacito" in the voice channel if ( interaction . commandName === "play" ) { if ( ! interaction . member . voice . channelId ) return await interaction . reply ( { content: "Yous are non in a voice channel!" , imperceptible: true } ) ; if ( interaction . guild . me . phonation . channelId && interaction . fellow member . voice . channelId !== interaction . lodge . me . voice . channelId ) render expect interaction . reply ( { content: "You are not in my vocalism channel!" , ephemeral: true } ) ; const query = interaction . options . get ( "query" ) . value ; const queue = role player . createQueue ( interaction . order , { metadata: { channel: interaction . channel } } ) ; // verify vc connectedness try { if ( ! queue . connection ) expect queue . connect ( interaction . member . voice . channel ) ; } catch { queue . destroy ( ) ; return look interaction . answer ( { content: "Could non join your voice channel!" , ephemeral: truthful } ) ; } await interaction . deferReply ( ) ; const track = await player . search ( query , { requestedBy: interaction . user } ) . so ( x => ten . tracks [ 0 ] ) ; if ( ! track ) return await interaction . followUp ( { content: `❌ | Rails ** ${ query } ** not found!` } ) ; queue . play ( track ) ; return await interaction . followUp ( { content: `⏱️ | Loading track ** ${ track . title } **!` } ) ; } } ) ; client . login ( process . env . DISCORD_TOKEN ) ;
Supported websites
By default, discord-player supports YouTube, Spotify and SoundCloud streams but.
Optional dependencies
Discord Player provides an Extractor API that enables you to use your custom stream extractor with it. Some packages have been made by the community to add new features using this API.
@discord-player/extractor (optional)
Optional package that adds support for vimeo
, reverbnation
, facebook
, zipper links
and lyrics
. You just need to install information technology using npm i --salvage @discord-player/extractor
(discord-player volition automatically discover and employ it).
@discord-player/downloader (optional)
@discord-player/downloader
is an optional package that brings support for +700 websites. The documentation is available here.
Examples of bots fabricated with Discord Player
These bots are made by the customs, they tin can help you build your own!
- Discord Music Bot by Androz2091
- Dodong by nizeic
- Musico by Whirl21
- Eyesense-Music-Bot by naseif
- Music-bot past ZerioDev
- AtlantaBot past Androz2091 (outdated)
- Discord-Music by inhydrox (outdated)
Advanced
Smooth Volume
Discord Histrion will by default effort to implement this. If smooth book does not work, you lot need to add this line at the top of your main file:
// CJS crave ( "discord-role player/smoothVolume" ) ; // ESM import "discord-thespian/smoothVolume"
⚠️ Make certain that line is situated at the TOP of your main file.
Employ cookies
const histrion = new Player ( client , { ytdlOptions: { requestOptions: { headers: { cookie: "YOUR_YOUTUBE_COOKIE" } } } } ) ;
Use custom proxies
const HttpsProxyAgent = require ( "https-proxy-amanuensis" ) ; // Remove "user:pass@" if y'all don't need to authenticate to your proxy. const proxy = "http://user:laissez passer@111.111.111.111:8080" ; const agent = HttpsProxyAgent ( proxy ) ; const player = new Histrion ( customer , { ytdlOptions: { requestOptions: { amanuensis } } } ) ;
You may too create a unproblematic proxy server and forward requests through information technology. Encounter https://github.com/http-party/node-http-proxy for more info.
Custom stream Engine
Discord Player by default uses node-ytdl-core for youtube and some other extractors for other sources. If you need to modify this behavior without touching extractors, you need to employ createStream
functionality of discord thespian. Here's an example on how you tin use play-dl to download youtube streams instead of using ytdl-core.
const playdl = crave ( "play-dl" ) ; // other code const queue = player . createQueue (..., { ..., async onBeforeCreateStream ( rails , source , _queue ) { // only trap youtube source if ( source === "youtube" ) { // rails here would be youtube track return ( await playdl . stream ( track . url , { discordPlayerCompatibility : true } ) ) . stream ; // we must return readable stream or void (returning void ways telling discord-actor to look for default extractor) } } } ) ;
<Queue>.onBeforeCreateStream
is called before actually downloading the stream. It is a dissimilar concept from extractors, where you are merely downloading streams. source
hither will exist a video source. Streams from onBeforeCreateStream
are so piped to FFmpeg
and finally sent to Discord vox servers.
Source: https://www.npmjs.com/package/discord-player
0 Response to "Discord Cannot Read Property Isforcused of Null"
Post a Comment