2022-07-31 20:43:08 +05:00
/ *
Thanks to discord - together = )
List of IDs from here : https : //gist.github.com/GeneralSadaf/42d91a2b6a93a7db7a39208f2d8b53ad
* /
const fetch = require ( "node-fetch" ) ;
const defaultApplications = [
{ id : "880218394199220334" , name : "Watch Together" , nitro _requirement : false , premium _tier _level : 0 , max _participants : - 1 , use : true } ,
{ id : "902271654783242291" , name : "Sketch Heads" , nitro _requirement : false , premium _tier _level : 0 , max _participants : 8 , use : true } ,
{ id : "879863976006127627" , name : "Word Snacks" , nitro _requirement : false , premium _tier _level : 0 , max _participants : 8 , use : true } ,
{ id : "878067389634314250" , name : "Doodle Crew" , nitro _requirement : false , premium _tier _level : 0 , max _participants : 16 , use : true } , // not in Discord Games Lab guild
{ id : "755827207812677713" , name : "Poker Night" , nitro _requirement : false , premium _tier _level : 1 , max _participants : 7 , use : true } ,
{ id : "832012774040141894" , name : "Chess In The Park" , nitro _requirement : false , premium _tier _level : 1 , max _participants : - 1 , use : true } ,
{ id : "879863686565621790" , name : "Letter League" , nitro _requirement : false , premium _tier _level : 1 , max _participants : 8 , use : true } ,
{ id : "852509694341283871" , name : "SpellCast" , nitro _requirement : false , premium _tier _level : 1 , max _participants : 6 , use : true } ,
{ id : "832013003968348200" , name : "Checkers In The Park" , nitro _requirement : false , premium _tier _level : 1 , max _participants : - 1 , use : true } ,
{ id : "832025144389533716" , name : "Blazing 8s" , nitro _requirement : false , premium _tier _level : 1 , max _participants : 8 , use : true } ,
{ id : "945737671223947305" , name : "Putt Party" , nitro _requirement : false , premium _tier _level : 1 , max _participants : 8 , use : true } ,
{ id : "903769130790969345" , name : "Land-io" , nitro _requirement : false , premium _tier _level : 1 , max _participants : 16 , use : true } ,
{ id : "947957217959759964" , name : "Bobble League" , nitro _requirement : false , premium _tier _level : 1 , max _participants : 8 , use : true } ,
{ id : "976052223358406656" , name : "Ask Away" , nitro _requirement : false , premium _tier _level : 1 , max _participants : 10 , use : true } ,
{ id : "950505761862189096" , name : "Know What I Meme" , nitro _requirement : false , premium _tier _level : 1 , max _participants : 8 , use : true } ,
// not public
/ *
{ id : "773336526917861400" , name : "Betrayal.io" , nitro _requirement : false , premium _tier _level : 0 , max _participants : null , use : false } ,
{ id : "814288819477020702" , name : "Fishington.io" , nitro _requirement : false , premium _tier _level : 0 , max _participants : null , use : false } ,
{ id : "879864070101172255" , name : "Sketchy Artist" , nitro _requirement : false , premium _tier _level : 0 , max _participants : 12 , use : false } ,
{ id : "879863881349087252" , name : "Awkword" , nitro _requirement : false , premium _tier _level : 0 , max _participants : 12 , use : false } ,
* /
] ;
/ * *
* Class symbolizing a DiscordTogether
* @ template { Object . < String , String > } T
* /
class DiscordTogether {
/ * *
* Create a new DiscordTogether
* @ param { import ( "../base/JaBa" ) } client
* @ param { T } applications
* @ example
* const Discord = require ( "discord.js" ) ;
* const client = new Discord . Client ( { intents : [ Discord . Intents . FLAGS . GUILDS , Discord . Intents . FLAGS . GUILD _MESSAGES ] } ) ;
* const { DiscordTogether } = require ( "discord-together" ) ;
*
* client . discordTogether = new DiscordTogether ( client ) ;
*
* client . on ( "message" , async message => {
* if ( message . content === "start" ) {
* client . discordTogether . createTogetherCode ( message . member . voice . channelID , "puttparty" ) . then ( async invite => {
* return message . channel . send ( ` ${ invite . code } ` ) ;
* } ) ;
* } ;
* } ) ;
*
* client . login ( "your token" ) ;
* /
constructor ( client ) {
if ( ! client ) throw new SyntaxError ( "Invalid Discord.Client !" ) ;
/ * *
* Discord . Client
* /
this . client = client ;
/ * *
* Discord Together applications
* /
this . applications = defaultApplications ;
}
/ * *
* Create a Discord Together invite code ( note : send the invite using markdown link )
* @ param { String } voiceChannelId
* @ param { keyof ( defaultApplications & T ) } option
* @ example
* client . on ( "message" , async message => {
* if ( message . content === "start" ) {
* client . discordTogether . createTogetherCode ( message . member . voice . channelID , "youtube" ) . then ( async invite => {
* return message . channel . send ( ` ${ invite . code } ` ) ; // Click the blue link
* } ) ;
* } ;
* } ) ;
* @ returns { Promise < { code : String ; } > }
* /
async createTogetherCode ( voiceChannelId , option ) {
/ * *
* @ param { String } code The invite link ( only use the blue link )
* /
2022-08-29 21:31:36 +05:00
const returnData = { code : "none" } ;
2022-07-31 20:43:08 +05:00
if ( option && this . applications . find ( apps => apps . id === option ) . id ) {
const applicationID = this . applications . find ( apps => apps . id === option ) . id ;
try {
await fetch ( ` https://discord.com/api/v10/channels/ ${ voiceChannelId } /invites ` , {
method : "POST" ,
body : JSON . stringify ( {
max _age : 86400 ,
max _uses : 0 ,
temporary : false ,
target _type : 2 ,
2022-12-15 21:02:38 +05:00
target _application _id : applicationID ,
2022-07-31 20:43:08 +05:00
} ) ,
headers : {
Authorization : ` Bot ${ this . client . config . token } ` ,
"Content-Type" : "application/json" ,
} ,
2022-08-29 21:31:36 +05:00
} ) . then ( res => res . json ( ) )
. then ( invite => {
if ( invite . error || ! invite . code ) throw new Error ( "An error occured while retrieving data!" ) ;
2022-07-31 20:43:08 +05:00
if ( Number ( invite . code ) === 50013 ) console . warn ( "Your bot lacks permissions to perform that action" ) ;
returnData . code = ` https://discord.com/invite/ ${ invite . code } ` ;
} ) ;
} catch ( err ) {
throw new Error ( "An error occured while starting Youtube together !" ) ;
}
return returnData ;
} else {
2022-08-29 21:31:36 +05:00
throw new SyntaxError ( "Invalid option!" ) ;
2022-07-31 20:43:08 +05:00
}
}
}
2022-08-29 21:31:36 +05:00
module . exports = { DiscordTogether , defaultApplications } ;