use the new client.application.commands to generate slash command interfaces

This commit is contained in:
Nathaniel Mason 2022-04-22 02:53:03 +01:00
parent e315feb737
commit e3318d26c7
27 changed files with 184 additions and 13 deletions

View File

@ -1,8 +1,15 @@
const { Constants } = require('discord.js');
module.exports = { module.exports = {
name: require('path').parse(__filename).name, name: require('path').parse(__filename).name,
description: 'Ask Anitrox a question, any question! and they will answer it!', description: 'Ask Anitrox a question, any question! and they will answer it!',
syntax: ['[Question]'], options: [{
name: 'question',
description: 'The question to ask Anitrox',
required: true,
type: Constants.ApplicationCommandOptionTypes.STRING
}],
async execute (client, message, args, config) { async execute (client, message, args, config) {
const index = Math.floor(Math.random() * config.answers.length); const index = Math.floor(Math.random() * config.answers.length);

View File

@ -1,7 +1,21 @@
const { Constants } = require('discord.js');
module.exports = { module.exports = {
name: require('path').parse(__filename).name, name: require('path').parse(__filename).name,
description: "Gets a user's avatar.", description: "Gets a user's avatar.",
options: [{
name: 'user',
description: 'Another user',
required: false,
type: Constants.ApplicationCommandOptionTypes.USER
},
{
name: 'userid',
description: "Another user's ID",
required: false,
type: Constants.ApplicationCommandOptionTypes.INTEGER
}],
async execute (client, message, args, config) { async execute (client, message, args, config) {
const user = message.mentions.users.first() || client.users.cache.get(args[0]) || message.author; const user = message.mentions.users.first() || client.users.cache.get(args[0]) || message.author;

View File

@ -1,7 +1,15 @@
const { Constants } = require('discord.js');
module.exports = { module.exports = {
name: require('path').parse(__filename).name, name: require('path').parse(__filename).name,
description: 'Bonks a user!', description: 'Bonks a user!',
options: [{
name: 'user',
description: 'The user to bonk',
required: true,
type: Constants.ApplicationCommandOptionTypes.USER
}],
async execute (client, message, _, config) { async execute (client, message, _, config) {
const taggedUser = message.mentions.users.first(); const taggedUser = message.mentions.users.first();

View File

@ -1,7 +1,15 @@
const { Constants } = require('discord.js');
module.exports = { module.exports = {
name: require('path').parse(__filename).name, name: require('path').parse(__filename).name,
description: 'Cheese an user, or run just ``n!cheese`` for a surprise :eyes:', description: 'Cheese a user, or run with no arguments for a surprise :eyes:',
options: [{
name: 'user',
description: 'The user to cheese',
required: false,
type: Constants.ApplicationCommandOptionTypes.USER
}],
async execute (_0, message, _1, config) { async execute (_0, message, _1, config) {
const taggedUser = message.mentions.users.first(); const taggedUser = message.mentions.users.first();

View File

@ -2,6 +2,7 @@ module.exports = {
name: require('path').parse(__filename).name, name: require('path').parse(__filename).name,
description: 'Give some lines of input, and get one back at random', description: 'Give some lines of input, and get one back at random',
options: [],
async execute (client, message, _, config) { async execute (client, message, _, config) {
const avatarURL = message.author.displayAvatarURL(); const avatarURL = message.author.displayAvatarURL();

View File

@ -2,6 +2,7 @@ module.exports = {
name: require('path').parse(__filename).name, name: require('path').parse(__filename).name,
description: 'Attributions to open source components used by Anitrox', description: 'Attributions to open source components used by Anitrox',
options: [],
async execute (_0, message, _1, config) { async execute (_0, message, _1, config) {
await message.channel.send({ await message.channel.send({

View File

@ -1,3 +1,5 @@
const { Constants } = require('discord.js');
const gifchoices = [ const gifchoices = [
'https://i.pinimg.com/originals/4d/89/d7/4d89d7f963b41a416ec8a55230dab31b.gif', 'https://i.pinimg.com/originals/4d/89/d7/4d89d7f963b41a416ec8a55230dab31b.gif',
'https://media1.tenor.com/images/6d73b0a9cadef5310be4b6160d2f959a/tenor.gif?itemid=12099823', 'https://media1.tenor.com/images/6d73b0a9cadef5310be4b6160d2f959a/tenor.gif?itemid=12099823',
@ -9,6 +11,12 @@ module.exports = {
name: require('path').parse(__filename).name, name: require('path').parse(__filename).name,
description: 'Cuddle a user!', description: 'Cuddle a user!',
options: [{
name: 'user',
description: 'The user to cuddle',
required: true,
type: Constants.ApplicationCommandOptionTypes.USER
}],
async execute (client, message, _, config) { async execute (client, message, _, config) {
const taggedUser = message.mentions.users.first(); const taggedUser = message.mentions.users.first();

View File

@ -1,9 +1,17 @@
const { Constants } = require('discord.js');
const { inspect } = require('util'); const { inspect } = require('util');
module.exports = { module.exports = {
name: require('path').parse(__filename).name, name: require('path').parse(__filename).name,
description: 'Executes JS code', description: 'Executes JS code',
options: [{
name: 'text',
description: 'The string to evaluate',
required: true,
type: Constants.ApplicationCommandOptionTypes.STRING
}],
async execute (_, message, args, config) { async execute (_, message, args, config) {
if (message.author.id === config.ownerID) { if (message.author.id === config.ownerID) {

View File

@ -2,7 +2,7 @@ module.exports = {
name: require('path').parse(__filename).name, name: require('path').parse(__filename).name,
description: 'Get help on anything from commands, to what the bot does! just not your homework..', description: 'Get help on anything from commands, to what the bot does! just not your homework..',
syntax: '<Command>', options: [],
async execute (_0, message, _1, config) { async execute (_0, message, _1, config) {
await message.channel.send({ await message.channel.send({

View File

@ -1,3 +1,5 @@
const { Constants } = require('discord.js');
const gifchoices = [ const gifchoices = [
'https://cdn.discordapp.com/attachments/803658122299572255/807670647920001044/hug2.gif', 'https://cdn.discordapp.com/attachments/803658122299572255/807670647920001044/hug2.gif',
'https://cdn.discordapp.com/attachments/803658122299572255/807670797983285268/hug1.gif', 'https://cdn.discordapp.com/attachments/803658122299572255/807670797983285268/hug1.gif',
@ -10,6 +12,12 @@ module.exports = {
name: require('path').parse(__filename).name, name: require('path').parse(__filename).name,
description: 'Hugs a user!', description: 'Hugs a user!',
options: [{
name: 'user',
description: 'The user to hug',
required: true,
type: Constants.ApplicationCommandOptionTypes.USER
}],
async execute (client, message, _, config) { async execute (client, message, _, config) {
const taggedUser = message.mentions.users.first(); const taggedUser = message.mentions.users.first();

View File

@ -18,6 +18,7 @@ module.exports = {
name: require('path').parse(__filename).name, name: require('path').parse(__filename).name,
description: 'Shows bot and host information', description: 'Shows bot and host information',
options: [],
async execute (client, message, _, config) { async execute (client, message, _, config) {
const os = require('os'); const os = require('os');

View File

@ -2,7 +2,7 @@ module.exports = {
name: require('path').parse(__filename).name, name: require('path').parse(__filename).name,
description: 'Add Anitrox to your beautiful server!', description: 'Add Anitrox to your beautiful server!',
syntax: [], options: [],
async execute (_0, message, _1, config) { async execute (_0, message, _1, config) {
await message.channel.send({ await message.channel.send({

View File

@ -1,3 +1,5 @@
const { Constants } = require('discord.js');
const gifchoices = [ const gifchoices = [
'https://cdn.discordapp.com/attachments/803658122299572255/807671954055626812/kiss5.gif', 'https://cdn.discordapp.com/attachments/803658122299572255/807671954055626812/kiss5.gif',
'https://cdn.discordapp.com/attachments/803658122299572255/807671956236140554/kiss2.gif', 'https://cdn.discordapp.com/attachments/803658122299572255/807671956236140554/kiss2.gif',
@ -10,6 +12,12 @@ module.exports = {
name: require('path').parse(__filename).name, name: require('path').parse(__filename).name,
description: 'Kisses a user!', description: 'Kisses a user!',
options: [{
name: 'user',
description: 'The user to kiss',
required: true,
type: Constants.ApplicationCommandOptionTypes.USER
}],
async execute (client, message, _, config) { async execute (client, message, _, config) {
const taggedUser = message.mentions.users.first(); const taggedUser = message.mentions.users.first();

View File

@ -1,3 +1,5 @@
const { Constants } = require('discord.js');
const gifchoices = [ const gifchoices = [
'https://cdn.discordapp.com/attachments/793537380330111028/803833954750038066/gif5.gif', 'https://cdn.discordapp.com/attachments/793537380330111028/803833954750038066/gif5.gif',
'https://cdn.discordapp.com/attachments/793537380330111028/803833959338475550/gif12.gif', 'https://cdn.discordapp.com/attachments/793537380330111028/803833959338475550/gif12.gif',
@ -20,6 +22,12 @@ module.exports = {
name: require('path').parse(__filename).name, name: require('path').parse(__filename).name,
description: 'Lesbian kiss <:lesbian:803831629428686849>', description: 'Lesbian kiss <:lesbian:803831629428686849>',
options: [{
name: 'user',
description: 'The user to kiss',
required: true,
type: Constants.ApplicationCommandOptionTypes.USER
}],
async execute (client, message, _, config) { async execute (client, message, _, config) {
const taggedUser = message.mentions.users.first(); const taggedUser = message.mentions.users.first();

View File

@ -1,3 +1,5 @@
const { Constants } = require('discord.js');
const gifchoices = [ const gifchoices = [
'https://cdn.discordapp.com/attachments/803658122299572255/805314244123951114/cef569820773b0f5d54ee34cfa18e1f8.gif', 'https://cdn.discordapp.com/attachments/803658122299572255/805314244123951114/cef569820773b0f5d54ee34cfa18e1f8.gif',
'https://cdn.lowgif.com/full/2027501b8fa5225c-.gif', 'https://cdn.lowgif.com/full/2027501b8fa5225c-.gif',
@ -9,6 +11,12 @@ module.exports = {
name: require('path').parse(__filename).name, name: require('path').parse(__filename).name,
description: 'Licks a user!', description: 'Licks a user!',
options: [{
name: 'user',
description: 'The user to lick',
required: true,
type: Constants.ApplicationCommandOptionTypes.USER
}],
async execute (client, message, _, config) { async execute (client, message, _, config) {
const taggedUser = message.mentions.users.first(); const taggedUser = message.mentions.users.first();

View File

@ -1,3 +1,5 @@
const { Constants } = require('discord.js');
const gifchoices = [ const gifchoices = [
'https://i.imgur.com/Ns1RBzX.gif', 'https://i.imgur.com/Ns1RBzX.gif',
'https://cdn.lowgif.com/full/2027501b8fa5225c-.gif', 'https://cdn.lowgif.com/full/2027501b8fa5225c-.gif',
@ -9,6 +11,12 @@ module.exports = {
name: require('path').parse(__filename).name, name: require('path').parse(__filename).name,
description: 'Noms an user!', description: 'Noms an user!',
options: [{
name: 'user',
description: 'The user to nom',
required: true,
type: Constants.ApplicationCommandOptionTypes.USER
}],
async execute (client, message, _, config) { async execute (client, message, _, config) {
const taggedUser = message.mentions.users.first(); const taggedUser = message.mentions.users.first();

View File

@ -1,3 +1,5 @@
const { Constants } = require('discord.js');
const gifchoices = [ const gifchoices = [
'https://cdn.discordapp.com/attachments/803658122299572255/803708174293008474/tenor.gif', 'https://cdn.discordapp.com/attachments/803658122299572255/803708174293008474/tenor.gif',
'https://community.gamepress.gg/uploads/default/original/3X/0/a/0a762099c5ad6de9ca5f13dd22a7e45884a99eb3.gif', 'https://community.gamepress.gg/uploads/default/original/3X/0/a/0a762099c5ad6de9ca5f13dd22a7e45884a99eb3.gif',
@ -8,6 +10,12 @@ module.exports = {
name: require('path').parse(__filename).name, name: require('path').parse(__filename).name,
description: 'Pats a user!', description: 'Pats a user!',
options: [{
name: 'user',
description: 'The user to pat',
required: true,
type: Constants.ApplicationCommandOptionTypes.USER
}],
async execute (client, message, _, config) { async execute (client, message, _, config) {
const taggedUser = message.mentions.users.first(); const taggedUser = message.mentions.users.first();

View File

@ -2,6 +2,7 @@ module.exports = {
name: require('path').parse(__filename).name, name: require('path').parse(__filename).name,
description: 'Gets bot ping', description: 'Gets bot ping',
options: [],
async execute (client, message, _, config) { async execute (client, message, _, config) {
const index = Math.floor(Math.random() * config.locations.length); const index = Math.floor(Math.random() * config.locations.length);

View File

@ -1,3 +1,5 @@
const { Constants } = require('discord.js');
const gifchoices = [ const gifchoices = [
'https://i.pinimg.com/originals/b4/95/fb/b495fb19f4b9a1b04f48297b676c497b.gif', 'https://i.pinimg.com/originals/b4/95/fb/b495fb19f4b9a1b04f48297b676c497b.gif',
'https://i.imgur.com/H7Ok5tn.gif', 'https://i.imgur.com/H7Ok5tn.gif',
@ -8,6 +10,12 @@ module.exports = {
name: require('path').parse(__filename).name, name: require('path').parse(__filename).name,
description: 'Pokes a user!', description: 'Pokes a user!',
options: [{
name: 'user',
description: 'The user to poke',
required: true,
type: Constants.ApplicationCommandOptionTypes.USER
}],
async execute (client, message, _, config) { async execute (client, message, _, config) {
const taggedUser = message.mentions.users.first(); const taggedUser = message.mentions.users.first();

View File

@ -2,6 +2,7 @@ module.exports = {
name: require('path').parse(__filename).name, name: require('path').parse(__filename).name,
description: 'Reloads a command', description: 'Reloads a command',
options: [],
async execute (client, message, args, config) { async execute (client, message, args, config) {
const avatarURL = message.author.displayAvatarURL(); const avatarURL = message.author.displayAvatarURL();

View File

@ -2,6 +2,7 @@ module.exports = {
name: require('path').parse(__filename).name, name: require('path').parse(__filename).name,
description: 'Restarts the bot', description: 'Restarts the bot',
options: [],
async execute (client, message, _, config) { async execute (client, message, _, config) {
if (message.author.id === config.ownerID) { if (message.author.id === config.ownerID) {

View File

@ -1,7 +1,15 @@
const { Constants } = require('discord.js');
module.exports = { module.exports = {
name: require('path').parse(__filename).name, name: require('path').parse(__filename).name,
description: 'Sets your nickname', description: 'Sets your nickname',
options: [{
name: 'name',
description: 'The new nickname',
required: true,
type: Constants.ApplicationCommandOptionTypes.STRING
}],
async execute (client, message, args, config) { async execute (client, message, args, config) {
const avatarURL = message.author.displayAvatarURL(); const avatarURL = message.author.displayAvatarURL();

View File

@ -1,7 +1,15 @@
const { Constants } = require('discord.js');
module.exports = { module.exports = {
name: require('path').parse(__filename).name, name: require('path').parse(__filename).name,
description: 'Slaps an user!', description: 'Slaps an user!',
options: [{
name: 'user',
description: 'The user to slap',
required: true,
type: Constants.ApplicationCommandOptionTypes.USER
}],
async execute (client, message, _, config) { async execute (client, message, _, config) {
const taggedUser = message.mentions.users.first(); const taggedUser = message.mentions.users.first();

View File

@ -1,3 +1,5 @@
const { Constants } = require('discord.js');
const gifchoices = [ const gifchoices = [
'https://media.discordapp.net/attachments/803658122299572255/806775382995894282/anime-couple-snuggle-gif-5.gif?width=450&height=238', 'https://media.discordapp.net/attachments/803658122299572255/806775382995894282/anime-couple-snuggle-gif-5.gif?width=450&height=238',
'https://media.discordapp.net/attachments/803658122299572255/806775411928989726/snuggl1.gif', 'https://media.discordapp.net/attachments/803658122299572255/806775411928989726/snuggl1.gif',
@ -8,6 +10,12 @@ module.exports = {
name: require('path').parse(__filename).name, name: require('path').parse(__filename).name,
description: 'Snuggle an user!', description: 'Snuggle an user!',
options: [{
name: 'user',
description: 'The user to snuggle',
required: true,
type: Constants.ApplicationCommandOptionTypes.USER
}],
async execute (client, message, _, config) { async execute (client, message, _, config) {
const taggedUser = message.mentions.users.first(); const taggedUser = message.mentions.users.first();

View File

@ -2,6 +2,7 @@ module.exports = {
name: require('path').parse(__filename).name, name: require('path').parse(__filename).name,
description: "IT'S TIME TO STOP!... the bot", description: "IT'S TIME TO STOP!... the bot",
options: [],
async execute (_0, message, _1, config) { async execute (_0, message, _1, config) {
if (message.author.id === config.ownerID) { if (message.author.id === config.ownerID) {

View File

@ -1,8 +1,21 @@
const { Constants } = require('discord.js');
module.exports = { module.exports = {
name: require('path').parse(__filename).name, name: require('path').parse(__filename).name,
description: 'Gets info about an user, such as ID, Discord Join date and more', description: 'Gets info about an user, such as ID, Discord Join date and more',
syntax: '<User>', options: [{
name: 'user',
description: 'Another user',
required: false,
type: Constants.ApplicationCommandOptionTypes.USER
},
{
name: 'userid',
description: "Another user's ID",
required: false,
type: Constants.ApplicationCommandOptionTypes.INTEGER
}],
async execute (_0, message, _1, config) { async execute (_0, message, _1, config) {
const user = message.mentions.users.first() || message.member; const user = message.mentions.users.first() || message.member;

View File

@ -5,14 +5,12 @@ const Discord = require('discord.js');
const config = require('./config.json'); const config = require('./config.json');
console.log('Starting!'); console.log('Starting!');
const client = new Discord.Client({ intents: config.intents.map(intent => eval(`Discord.Intents.FLAGS.${intent}`)) }); const client = new Discord.Client({ intents: config.intents.map(intent => eval(`Discord.Intents.FLAGS.${intent}`)) });
client.commands = new Discord.Collection(); client.commands = new Discord.Collection();
fs.readdirSync('./commands').filter(file => file.endsWith('.js')).forEach(file => {
const commandFiles = fs.readdirSync('./commands').filter(file => file.endsWith('.js'));
for (const file of commandFiles) {
const command = require(`./commands/${file}`); const command = require(`./commands/${file}`);
client.commands.set(command.name, command); client.commands.set(command.name, command);
} });
client.generateErrorMessage = (errorMsg, avatarURL) => ({ client.generateErrorMessage = (errorMsg, avatarURL) => ({
embeds: [{ embeds: [{
@ -33,8 +31,28 @@ client.generateErrorMessage = (errorMsg, avatarURL) => ({
client.on('error', (e) => console.log(`[ERROR] ${e}`)); client.on('error', (e) => console.log(`[ERROR] ${e}`));
client.on('warn', (e) => (`[WARN] ${e}`)); client.on('warn', (e) => (`[WARN] ${e}`));
client.once('ready', () => { client.once('ready', async () => {
console.clear(); const commands = config.sandbox ? client.guilds.cache.get(config.sandboxGuild)?.commands : client.application.commands;
if (config.sandbox) {
console.log('deleting previous commands from sandbox');
const localCommands = await commands.fetch();
localCommands.forEach(async x => {
await commands.delete(x);
});
// console.log('deleting global commands');
// const globalCommands = await client.application.commands.fetch();
// globalCommands.forEach(async x => {
// await client.application.commands.delete(x);
// });
}
client.commands.forEach(async command => {
await commands.create(command);
});
// console.clear();
console.log(' ___ _ __ '); console.log(' ___ _ __ ');
console.log(' / | ____ (_) /__________ _ __'); console.log(' / | ____ (_) /__________ _ __');
console.log(' / /| | / __ \\/ / __/ ___/ __ \\| |/_/'); console.log(' / /| | / __ \\/ / __/ ___/ __ \\| |/_/');
@ -62,7 +80,7 @@ client.on('messageCreate', async (message) => {
try { try {
await client.commands.get(command).execute(client, message, args, config); await client.commands.get(command).execute(client, message, args, config);
} catch (error) { } catch (error) {
console.stack(); console.trace();
message.channel.send({ message.channel.send({
embeds: [{ embeds: [{
title: '<:AnitroxError:809651936563429416> **Something went wrong!**', title: '<:AnitroxError:809651936563429416> **Something went wrong!**',