1+ //Import the Module directly, as with an forc ;) as well as discord.js and create a new client for discord bot & memer Bot
2+ const Meme = require ( "meme-api" ) ,
3+ Discord = require ( "discord.js" ) ,
4+ client = new Discord . Client ( ) ,
5+ memer = new Meme ( ) ;
6+
7+ //login to the Discord Bot
8+ client . login ( "YOUR DISCORD BOT TOKEN GOES HERE" ) ;
9+
10+ //Read Event
11+ client . on ( "ready" , ( ) => {
12+ console . log ( "Memer is online!" ) ; // eslint-disable-line no-console
13+ } ) ;
14+
15+ //Log Message
16+ client . on ( "message" , ( message ) => {
17+ //if in a dm or msg from a bot, return
18+ if ( ! message . guild || message . author . bot ) return ;
19+
20+ const args = message . content . slice ( "!" . length ) . split ( " " ) ;
21+ const cmd = args . shift ( ) . toLowerCase ( ) ;
22+ //Example Command useage: !abandon <TEXT>
23+ if ( cmd === "abandon" ) {
24+ if ( ! args [ 0 ] ) return message . reply ( "Unknown useage, try this: `!abandon <TEXT>`" ) ;
25+ //create image and send it in the channel with the added arguments to the command
26+ memer . abandon ( args . join ( " " ) ) . then ( image => {
27+ const attachment = new Discord . MessageAttachment ( image , "abandon.png" ) ;
28+ return message . channel . send ( attachment ) ;
29+ } ) . catch ( e => {
30+ message . channel . send ( String ( e ) . substr ( 0 , 2000 ) , { code : "js" } )
31+ } )
32+ }
33+
34+ } ) ;
0 commit comments