Every line of 'npm discord js' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.
23 async main (message, [query, branch = 'stable']) { 24 await this.search(message, query, 'main', branch) 25 }
12 public constructor () { 13 this.client = new Discord.Client() 14 15 this.client.on( 16 'ready', 17 (): void => { 18 console.log('Discord bot initialized') 19 this.channel = this.client.channels.get( 20 '334977257456271360' 21 ) as Discord.TextChannel 22 this.faqChannel = this.client.channels.get( 23 FAQ_ID 24 ) as Discord.TextChannel 25 this.updateFAQ() 26 } 27 ) 28 29 this.client.on( 30 'guildMemberAdd', 31 (member: Discord.Client): void => { 32 ;(this.channel as any).send( 33 `User "${member.user.username}" has joined the server` 34 ) 35 } 36 ) 37 38 this.client.on( 39 'guildMemberRemove', 40 (member: Discord.Client): void => { 41 ;(this.channel as any).send( 42 `User "${member.user.username}" has left the server` 43 ) 44 } 45 ) 46 }
31 async commando (message, [query]) { 32 await this.search(message, query, 'commando') 33 }
39 async run(msg, { query }) { 40 try { 41 const current = await request.get('https://xkcd.com/info.0.json'); 42 if (query === 'today') { 43 const embed = new MessageEmbed() 44 .setTitle(`${current.body.num} - ${current.body.title}`) 45 .setColor(0x9797FF) 46 .setURL(`https://xkcd.com/${current.body.num}`) 47 .setImage(current.body.img) 48 .setFooter(current.body.alt); 49 return msg.embed(embed); 50 } 51 if (query === 'random') { 52 const random = Math.floor(Math.random() * current.body.num) + 1; 53 const { body } = await request.get(`https://xkcd.com/${random}/info.0.json`); 54 const embed = new MessageEmbed() 55 .setTitle(`${body.num} - ${body.title}`) 56 .setColor(0x9797FF) 57 .setURL(`https://xkcd.com/${body.num}`) 58 .setImage(body.img) 59 .setFooter(body.alt); 60 return msg.embed(embed); 61 } 62 const choice = Number.parseInt(query, 10); 63 if (current.body.num < choice) return msg.say('Could not find any results.'); 64 const { body } = await request.get(`https://xkcd.com/${choice}/info.0.json`); 65 const embed = new MessageEmbed() 66 .setTitle(`${body.num} - ${body.title}`) 67 .setColor(0x9797FF) 68 .setURL(`https://xkcd.com/${body.num}`) 69 .setImage(body.img) 70 .setFooter(body.alt); 71 return msg.embed(embed); 72 } catch (err) { 73 return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`); 74 } 75 }