Browse Source

Fix config and add slash commands

master
Abheek Dhawan 3 years ago
parent
commit
1a5a7d1ac1
  1. 5
      config/authors.json
  2. 37
      config/slash.json
  3. 32
      index.js
  4. 43
      package-lock.json
  5. 1
      package.json

5
config/authors.json

@ -1,6 +1,3 @@
[ [
{ "745063586422063214"
"tag": "ADawesomeguy#3602",
"id": "745063586422063214"
}
] ]

37
config/slash.json

@ -0,0 +1,37 @@
[
{
"name": "joke",
"description": "Returns a joke with a given category",
"options": [
{
"type": "STRING",
"name": "category",
"description": "The category for the joke (none for any category)",
"default": "false",
"required": "false",
"choices": [
{
"name": "programming",
"value": "Programming"
},
{
"name": "miscellaneous",
"value": "Miscellaneous"
},
{
"name": "dark",
"value": "Dark"
},
{
"name": "spooky",
"value": "Spooky"
},
{
"name": "christmas",
"value": "Christmas"
}
]
}
]
}
]

32
index.js

@ -3,6 +3,8 @@ require('dotenv').config();
const Discord = require('discord.js'); const Discord = require('discord.js');
const client = new Discord.Client({ intents: ["GUILDS", "GUILD_MESSAGES"] }); const client = new Discord.Client({ intents: ["GUILDS", "GUILD_MESSAGES"] });
const axios = require('axios');
const slashcommands = require('./config/slash.json'); const slashcommands = require('./config/slash.json');
const authors = require('./config/authors.json'); const authors = require('./config/authors.json');
@ -12,7 +14,9 @@ client.on("ready", () => {
client.on("messageCreate", async message => { client.on("messageCreate", async message => {
if (message.author.bot) return; if (message.author.bot) return;
if (authors.includes(message.author.tag) && message.content.toLowerCase === "!deploy") { if (message.channel.type === "DM") return;
if (authors.includes(message.author.id) && message.content.toLowerCase() === "j.deploy") {
console.log("Updating slash commands...");
client.application.commands.set(slashcommands); client.application.commands.set(slashcommands);
} }
if (message.content.toLowerCase().includes("-ass ")) { if (message.content.toLowerCase().includes("-ass ")) {
@ -26,4 +30,30 @@ client.on("messageCreate", async message => {
} }
}); });
client.on("interactionCreate", async interaction => {
if (interaction.isCommand()) {
if (interaction.commandName === "joke") {
jokeCommand(interaction);
}
}
});
const jokeCommand = async interaction => {
interaction.deferReply();
let category;
interaction.options.get("category") ? category = interaction.options.get("category").value : category = "Any";
axios.get(`https://v2.jokeapi.dev/joke/${category}?blacklistFlags=nsfw,religious,political,racist,sexist,explicit`)
.then(async response => {
const data = response.data;
const jokeEmbed = new Discord.MessageEmbed().setAuthor(`Category: ${data.category}`);
if (data.type === "single") {
jokeEmbed.setDescription(data.joke);
} else if (data.type === "twopart") {
jokeEmbed.setTitle(data.setup);
jokeEmbed.setDescription(`||${data.delivery}||`);
}
await interaction.followUp({ embeds: [jokeEmbed] });
});
}
client.login(process.env.TOKEN); client.login(process.env.TOKEN);

43
package-lock.json

@ -7,8 +7,9 @@
"": { "": {
"name": "joker-bot", "name": "joker-bot",
"version": "1.0.0", "version": "1.0.0",
"license": "ISC", "license": "Apache-2.0",
"dependencies": { "dependencies": {
"axios": "^0.23.0",
"discord.js": "^13.2.0", "discord.js": "^13.2.0",
"dotenv": "^10.0.0" "dotenv": "^10.0.0"
} }
@ -96,6 +97,14 @@
"resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz", "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz",
"integrity": "sha1-x57Zf380y48robyXkLzDZkdLS3k=" "integrity": "sha1-x57Zf380y48robyXkLzDZkdLS3k="
}, },
"node_modules/axios": {
"version": "0.23.0",
"resolved": "https://registry.npmjs.org/axios/-/axios-0.23.0.tgz",
"integrity": "sha512-NmvAE4i0YAv5cKq8zlDoPd1VLKAqX5oLuZKs8xkJa4qi6RGn0uhCYFjWtHHC9EM/MwOwYWOs53W+V0aqEXq1sg==",
"dependencies": {
"follow-redirects": "^1.14.4"
}
},
"node_modules/callsites": { "node_modules/callsites": {
"version": "3.1.0", "version": "3.1.0",
"resolved": "https://registry.npmjs.org/callsites/-/callsites-3.1.0.tgz", "resolved": "https://registry.npmjs.org/callsites/-/callsites-3.1.0.tgz",
@ -172,6 +181,25 @@
"node": ">=10" "node": ">=10"
} }
}, },
"node_modules/follow-redirects": {
"version": "1.14.4",
"resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.14.4.tgz",
"integrity": "sha512-zwGkiSXC1MUJG/qmeIFH2HBJx9u0V46QGUe3YR1fXG8bXQxq7fLj0RjLZQ5nubr9qNJUZrH+xUcwXEoXNpfS+g==",
"funding": [
{
"type": "individual",
"url": "https://github.com/sponsors/RubenVerborgh"
}
],
"engines": {
"node": ">=4.0"
},
"peerDependenciesMeta": {
"debug": {
"optional": true
}
}
},
"node_modules/is-obj": { "node_modules/is-obj": {
"version": "2.0.0", "version": "2.0.0",
"resolved": "https://registry.npmjs.org/is-obj/-/is-obj-2.0.0.tgz", "resolved": "https://registry.npmjs.org/is-obj/-/is-obj-2.0.0.tgz",
@ -366,6 +394,14 @@
"resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz", "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz",
"integrity": "sha1-x57Zf380y48robyXkLzDZkdLS3k=" "integrity": "sha1-x57Zf380y48robyXkLzDZkdLS3k="
}, },
"axios": {
"version": "0.23.0",
"resolved": "https://registry.npmjs.org/axios/-/axios-0.23.0.tgz",
"integrity": "sha512-NmvAE4i0YAv5cKq8zlDoPd1VLKAqX5oLuZKs8xkJa4qi6RGn0uhCYFjWtHHC9EM/MwOwYWOs53W+V0aqEXq1sg==",
"requires": {
"follow-redirects": "^1.14.4"
}
},
"callsites": { "callsites": {
"version": "3.1.0", "version": "3.1.0",
"resolved": "https://registry.npmjs.org/callsites/-/callsites-3.1.0.tgz", "resolved": "https://registry.npmjs.org/callsites/-/callsites-3.1.0.tgz",
@ -417,6 +453,11 @@
"resolved": "https://registry.npmjs.org/dotenv/-/dotenv-10.0.0.tgz", "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-10.0.0.tgz",
"integrity": "sha512-rlBi9d8jpv9Sf1klPjNfFAuWDjKLwTIJJ/VxtoTwIR6hnZxcEOQCZg2oIL3MWBYw5GpUDKOEnND7LXTbIpQ03Q==" "integrity": "sha512-rlBi9d8jpv9Sf1klPjNfFAuWDjKLwTIJJ/VxtoTwIR6hnZxcEOQCZg2oIL3MWBYw5GpUDKOEnND7LXTbIpQ03Q=="
}, },
"follow-redirects": {
"version": "1.14.4",
"resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.14.4.tgz",
"integrity": "sha512-zwGkiSXC1MUJG/qmeIFH2HBJx9u0V46QGUe3YR1fXG8bXQxq7fLj0RjLZQ5nubr9qNJUZrH+xUcwXEoXNpfS+g=="
},
"is-obj": { "is-obj": {
"version": "2.0.0", "version": "2.0.0",
"resolved": "https://registry.npmjs.org/is-obj/-/is-obj-2.0.0.tgz", "resolved": "https://registry.npmjs.org/is-obj/-/is-obj-2.0.0.tgz",

1
package.json

@ -11,6 +11,7 @@
"author": "", "author": "",
"license": "Apache-2.0", "license": "Apache-2.0",
"dependencies": { "dependencies": {
"axios": "^0.23.0",
"discord.js": "^13.2.0", "discord.js": "^13.2.0",
"dotenv": "^10.0.0" "dotenv": "^10.0.0"
} }

Loading…
Cancel
Save