setting up gif Collection and getting bot functional
This commit is contained in:
parent
abe1097c0c
commit
b64d687802
7
commands/reload-gifs.js
Normal file
7
commands/reload-gifs.js
Normal file
@ -0,0 +1,7 @@
|
||||
module.exports = {
|
||||
name: "reload-gifs",
|
||||
description: "Refresh the hardcoded gif library.",
|
||||
execute(message, args) {
|
||||
getGifFiles();
|
||||
}
|
||||
}
|
4
gifs/dab.js
Normal file
4
gifs/dab.js
Normal file
@ -0,0 +1,4 @@
|
||||
module.exports = {
|
||||
name: "dab",
|
||||
embed_url: "https://giphy.com/embed/lae7QSMFxEkkE"
|
||||
}
|
4
gifs/nod.js
Normal file
4
gifs/nod.js
Normal file
@ -0,0 +1,4 @@
|
||||
module.exports = {
|
||||
name: "nod",
|
||||
embed_url: "https://tenor.com/view/smile-nod-yes-robert-redford-beard-gif-10489927"
|
||||
}
|
4
gifs/psh.js
Normal file
4
gifs/psh.js
Normal file
@ -0,0 +1,4 @@
|
||||
module.exports = {
|
||||
name: "psh",
|
||||
embed_url: "https://tenor.com/view/ed-bassmaster-youtuber-youtube-influencer-psh-gif-10556767"
|
||||
}
|
4
gifs/shedsalive.js
Normal file
4
gifs/shedsalive.js
Normal file
@ -0,0 +1,4 @@
|
||||
module.exports = {
|
||||
name: "shedsalive",
|
||||
embed_url: "https://giphy.com/embed/glL1yvxJ4KvYc"
|
||||
}
|
4
gifs/shedsdead.js
Normal file
4
gifs/shedsdead.js
Normal file
@ -0,0 +1,4 @@
|
||||
module.exports = {
|
||||
name: "shedsdead",
|
||||
embed_url: "http://voidf1sh.me/shedsdead.gif"
|
||||
}
|
3
gifs/template
Normal file
3
gifs/template
Normal file
@ -0,0 +1,3 @@
|
||||
module.exports = {
|
||||
|
||||
}
|
47
index.js
47
index.js
@ -6,11 +6,14 @@ dotenv.config();
|
||||
const Discord = require('discord.js');
|
||||
const client = new Discord.Client();
|
||||
client.commands = new Discord.Collection();
|
||||
client.gifs = new Discord.Collection();
|
||||
const debug = true;
|
||||
const config = require('./config.json');
|
||||
const { prefix, serverID } = require('./config.json');
|
||||
// const config = require('./config.json');
|
||||
const { prefix } = require('./config.json');
|
||||
const commandFiles = fs.readdirSync('./commands').filter(file => file.endsWith('.js'));
|
||||
const gifFiles = fs.readdirSync('./gifs').filter(file => file.endsWith('.js'));
|
||||
// const owner = process.env.ownerID;
|
||||
const giphy = require('giphy-api')(process.env.giphyAPIKey);
|
||||
|
||||
function getCommandFiles() {
|
||||
for (const file of commandFiles) {
|
||||
@ -20,6 +23,14 @@ function getCommandFiles() {
|
||||
if (debug) console.log(client.commands);
|
||||
}
|
||||
|
||||
function getGifFiles() {
|
||||
for (const file of gifFiles) {
|
||||
const gif = require(`./gifs/${file}`);
|
||||
client.gifs.set(gif.name, gif);
|
||||
}
|
||||
if (debug) console.log(client.gifs);
|
||||
}
|
||||
|
||||
function extCheck(content) {
|
||||
const lastFour = content.slice(-4);
|
||||
switch (lastFour) {
|
||||
@ -34,18 +45,19 @@ function extCheck(content) {
|
||||
|
||||
client.once('ready', () => {
|
||||
console.log('Ready');
|
||||
client.guilds.fetch(serverID)
|
||||
.then(guild => client.user.setActivity('Nod Simulator 2021', {type: "PLAYING"}))
|
||||
.catch(console.error);
|
||||
client.user.setActivity('Nod Simulator 2021', { type: 'PLAYING' }).then().catch(console.error);
|
||||
getCommandFiles();
|
||||
getGifFiles();
|
||||
});
|
||||
|
||||
client.login(process.env.TOKEN);
|
||||
|
||||
client.on('message', message => {
|
||||
if (debug) console.log(extCheck(message.content));
|
||||
if (!message.content.startsWith(prefix) || message.author.bot || !extCheck(message.content)) return;
|
||||
const ext = extCheck(message.content);
|
||||
if (debug) console.log(ext);
|
||||
if ((!message.content.startsWith(prefix) && ext == false) || message.author.bot) return;
|
||||
|
||||
if (message.content.startsWith(prefix)) {
|
||||
const args = message.content.slice(prefix.length).trim().split(/ +/);
|
||||
const command = args.shift().toLowerCase();
|
||||
|
||||
@ -55,6 +67,25 @@ client.on('message', message => {
|
||||
client.commands.get(command).execute(message, args);
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
message.reply('There was an error trying to execute that command.');
|
||||
message.channel.send('There was an error trying to execute that command.');
|
||||
}
|
||||
}
|
||||
|
||||
if (ext == 'gif') {
|
||||
const query = message.content.slice(0, -4);
|
||||
if (debug) console.log(query);
|
||||
|
||||
if (!client.gifs.has(query)) {
|
||||
giphy.search(query, (err, res) => {
|
||||
if (res.data[0] != undefined) {
|
||||
message.channel.send(res.data[0].embed_url).then().catch(console.error);
|
||||
} else {
|
||||
message.channel.send('I was unable to find a gif of ' + query);
|
||||
}
|
||||
if (err) console.error(err);
|
||||
});
|
||||
} else {
|
||||
message.channel.send(client.gifs.get(query).embed_url);
|
||||
}
|
||||
}
|
||||
});
|
Loading…
Reference in New Issue
Block a user