Skip to content

Commit

Permalink
added command handler
Browse files Browse the repository at this point in the history
  • Loading branch information
mushahidq committed Mar 20, 2021
1 parent bc2f974 commit 325ff6a
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 29 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# duelbot

a quiz bot for discord with a twist
a quiz bot for discord with a twist
32 changes: 10 additions & 22 deletions bot.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
require("dotenv").config()
const fs = require('fs')
const Discord = require("discord.js")
const client = new Discord.Client()
const { prefix, channelid } = require('./config.json')

client.commands = new Discord.Collection();
const commandFiles = fs.readdirSync('./commands').filter(file => file.endsWith('.js'));

for (const file of commandFiles) {
const command = require(`./commands/${file}`);
client.commands.set(command.name, command);
}

client.on("ready", () => {
console.log(`Logged in as ${client.user.tag}!`);
})
Expand All @@ -14,28 +23,7 @@ function gotMessage(msg) {

const args = msg.content.slice(prefix.length).trim().split(/ +/);
const command = args.shift().toLowerCase();
if (msg.channel.id == channelid && command === "ping") {
msg.channel.send("Pong");
} else if (msg.channel.id == channelid && command === "beep") {
msg.channel.send("Boop");
} else if (msg.channel.id == channelid && command === "server") {
msg.channel.send(`This server's name is: ${msg.guild.name}\nTotal members: ${msg.guild.memberCount}`);
} else if (msg.channel.id == channelid && command === "user-info") {
msg.channel.send(`Your username: ${msg.author.username}\nYour ID: ${msg.author.id}`);
} else if (msg.channel.id == channelid && command === "args-info") {
if (!args.length) {
return msg.channel.send(`You didn't provide any arguments, ${message.author}!`);
}
msg.channel.send(`Command name: ${command}\nArguments: ${args}`);
} else if (msg.channel.id == channelid && command === "duel") {
if(msg.mentions.users.size) {
const taggedUser = msg.mentions.users.first();
msg.channel.send(`${taggedUser}, you have been challenged to a duel by ${msg.author}.\nReact with your response.`);
}
else {
msg.channel.send(`${msg.author} You need to tag the user you want to challenge to a duel.`);
}
}

}

client.login(process.env.TOKEN)
14 changes: 8 additions & 6 deletions commands/duel.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ module.exports = {
name: 'duel',
despcription: "Challenge a player to a duel",
execute(message, args) {
if(message.mentions.users.size) {
const taggedUser = message.mentions.users.first();
message.channel.send(`${taggedUser}, you have been challenged to a duel by ${message.author}.\nReact with your response.`);
}
else {
message.channel.send(`${message.author} You need to tag the user you want to challenge to a duel.`);
if (message.channel.id == channelid) {
if(message.mentions.users.size) {
const taggedUser = message.mentions.users.first();
message.channel.send(`${taggedUser}, you have been challenged to a duel by ${message.author}.\nReact with your response.`);
}
else {
message.channel.send(`${message.author} You need to tag the user you want to challenge to a duel.`);
}
}
}
}
Empty file added commands/help.js
Empty file.
Empty file added commands/pirate-translate.js
Empty file.
Empty file.
11 changes: 11 additions & 0 deletions commands/user-info.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const { _, channelid } = require('../config.json')

module.exports = {
name: 'user-info',
description: "Gives the information about the user",
execute: async(message, args) => {
if (message.channel.id == channelid) {
message.channel.send(`Your username: ${message.author.username}\nYour ID: ${message.author.id}`)
}
}
}
17 changes: 17 additions & 0 deletions commands/yoda-translate.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
const { _, channelid } = require('../config.json')
const querystring = require('querystring')

module.exports = {
name: 'yoda-translate',
description: 'Translates a string to how Yoda would say it',
execute: async(message, args) =>{
if (message.channel.id == channelid) {
if (!args.length) {
return message.channel.send("You need to specify some text to convert");
}
const query = querystring.stringify({ term: args.join(' ') });
const { _, content } = await fetch(`https://api.funtranslations.com/translate/yoda.json?text=${query}`);
message.channel.send(content.translated);
}
}
}

0 comments on commit 325ff6a

Please sign in to comment.