Created
August 23, 2020 23:25
-
-
Save JasonMadeSomething/e25bccd138745c48258715c069fafd88 to your computer and use it in GitHub Desktop.
main bot file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require('dotenv').config() | |
const Discord = require('discord.js') | |
const axios = require('axios') | |
const Feats = require('./feats') | |
const Magic = require('./magic') | |
const client = new Discord.Client() | |
client.login(process.env.DISCORD_TOKEN) | |
const responders = [new Magic(), new Feats()] | |
client.on('message', getPage) | |
async function getPage (msg) { | |
const url = encodeURI(msg.content) | |
const responder = responders.find(responder => responder.match(url)) | |
if (!responder) { | |
} else { | |
try { | |
const response = await axios.get(url) | |
const message = responder.format(response) | |
msg.channel.send(message) | |
} catch (e) { | |
console.error(e) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment