use the new client.application.commands to generate slash command interfaces
This commit is contained in:
parent
e315feb737
commit
e3318d26c7
|
@ -1,8 +1,15 @@
|
|||
const { Constants } = require('discord.js');
|
||||
|
||||
module.exports = {
|
||||
|
||||
name: require('path').parse(__filename).name,
|
||||
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) {
|
||||
const index = Math.floor(Math.random() * config.answers.length);
|
||||
|
|
|
@ -1,7 +1,21 @@
|
|||
const { Constants } = require('discord.js');
|
||||
|
||||
module.exports = {
|
||||
|
||||
name: require('path').parse(__filename).name,
|
||||
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) {
|
||||
const user = message.mentions.users.first() || client.users.cache.get(args[0]) || message.author;
|
||||
|
|
|
@ -1,7 +1,15 @@
|
|||
const { Constants } = require('discord.js');
|
||||
|
||||
module.exports = {
|
||||
|
||||
name: require('path').parse(__filename).name,
|
||||
description: 'Bonks a user!',
|
||||
options: [{
|
||||
name: 'user',
|
||||
description: 'The user to bonk',
|
||||
required: true,
|
||||
type: Constants.ApplicationCommandOptionTypes.USER
|
||||
}],
|
||||
|
||||
async execute (client, message, _, config) {
|
||||
const taggedUser = message.mentions.users.first();
|
||||
|
|
|
@ -1,7 +1,15 @@
|
|||
const { Constants } = require('discord.js');
|
||||
|
||||
module.exports = {
|
||||
|
||||
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) {
|
||||
const taggedUser = message.mentions.users.first();
|
||||
|
|
|
@ -2,6 +2,7 @@ module.exports = {
|
|||
|
||||
name: require('path').parse(__filename).name,
|
||||
description: 'Give some lines of input, and get one back at random',
|
||||
options: [],
|
||||
|
||||
async execute (client, message, _, config) {
|
||||
const avatarURL = message.author.displayAvatarURL();
|
||||
|
|
|
@ -2,6 +2,7 @@ module.exports = {
|
|||
|
||||
name: require('path').parse(__filename).name,
|
||||
description: 'Attributions to open source components used by Anitrox',
|
||||
options: [],
|
||||
|
||||
async execute (_0, message, _1, config) {
|
||||
await message.channel.send({
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
const { Constants } = require('discord.js');
|
||||
|
||||
const gifchoices = [
|
||||
'https://i.pinimg.com/originals/4d/89/d7/4d89d7f963b41a416ec8a55230dab31b.gif',
|
||||
'https://media1.tenor.com/images/6d73b0a9cadef5310be4b6160d2f959a/tenor.gif?itemid=12099823',
|
||||
|
@ -9,6 +11,12 @@ module.exports = {
|
|||
|
||||
name: require('path').parse(__filename).name,
|
||||
description: 'Cuddle a user!',
|
||||
options: [{
|
||||
name: 'user',
|
||||
description: 'The user to cuddle',
|
||||
required: true,
|
||||
type: Constants.ApplicationCommandOptionTypes.USER
|
||||
}],
|
||||
|
||||
async execute (client, message, _, config) {
|
||||
const taggedUser = message.mentions.users.first();
|
||||
|
|
|
@ -1,9 +1,17 @@
|
|||
const { Constants } = require('discord.js');
|
||||
|
||||
const { inspect } = require('util');
|
||||
|
||||
module.exports = {
|
||||
|
||||
name: require('path').parse(__filename).name,
|
||||
description: 'Executes JS code',
|
||||
options: [{
|
||||
name: 'text',
|
||||
description: 'The string to evaluate',
|
||||
required: true,
|
||||
type: Constants.ApplicationCommandOptionTypes.STRING
|
||||
}],
|
||||
|
||||
async execute (_, message, args, config) {
|
||||
if (message.author.id === config.ownerID) {
|
||||
|
|
|
@ -2,7 +2,7 @@ module.exports = {
|
|||
|
||||
name: require('path').parse(__filename).name,
|
||||
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) {
|
||||
await message.channel.send({
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
const { Constants } = require('discord.js');
|
||||
|
||||
const gifchoices = [
|
||||
'https://cdn.discordapp.com/attachments/803658122299572255/807670647920001044/hug2.gif',
|
||||
'https://cdn.discordapp.com/attachments/803658122299572255/807670797983285268/hug1.gif',
|
||||
|
@ -10,6 +12,12 @@ module.exports = {
|
|||
|
||||
name: require('path').parse(__filename).name,
|
||||
description: 'Hugs a user!',
|
||||
options: [{
|
||||
name: 'user',
|
||||
description: 'The user to hug',
|
||||
required: true,
|
||||
type: Constants.ApplicationCommandOptionTypes.USER
|
||||
}],
|
||||
|
||||
async execute (client, message, _, config) {
|
||||
const taggedUser = message.mentions.users.first();
|
||||
|
|
|
@ -18,6 +18,7 @@ module.exports = {
|
|||
|
||||
name: require('path').parse(__filename).name,
|
||||
description: 'Shows bot and host information',
|
||||
options: [],
|
||||
|
||||
async execute (client, message, _, config) {
|
||||
const os = require('os');
|
||||
|
|
|
@ -2,7 +2,7 @@ module.exports = {
|
|||
|
||||
name: require('path').parse(__filename).name,
|
||||
description: 'Add Anitrox to your beautiful server!',
|
||||
syntax: [],
|
||||
options: [],
|
||||
|
||||
async execute (_0, message, _1, config) {
|
||||
await message.channel.send({
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
const { Constants } = require('discord.js');
|
||||
|
||||
const gifchoices = [
|
||||
'https://cdn.discordapp.com/attachments/803658122299572255/807671954055626812/kiss5.gif',
|
||||
'https://cdn.discordapp.com/attachments/803658122299572255/807671956236140554/kiss2.gif',
|
||||
|
@ -10,6 +12,12 @@ module.exports = {
|
|||
|
||||
name: require('path').parse(__filename).name,
|
||||
description: 'Kisses a user!',
|
||||
options: [{
|
||||
name: 'user',
|
||||
description: 'The user to kiss',
|
||||
required: true,
|
||||
type: Constants.ApplicationCommandOptionTypes.USER
|
||||
}],
|
||||
|
||||
async execute (client, message, _, config) {
|
||||
const taggedUser = message.mentions.users.first();
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
const { Constants } = require('discord.js');
|
||||
|
||||
const gifchoices = [
|
||||
'https://cdn.discordapp.com/attachments/793537380330111028/803833954750038066/gif5.gif',
|
||||
'https://cdn.discordapp.com/attachments/793537380330111028/803833959338475550/gif12.gif',
|
||||
|
@ -20,6 +22,12 @@ module.exports = {
|
|||
|
||||
name: require('path').parse(__filename).name,
|
||||
description: 'Lesbian kiss <:lesbian:803831629428686849>',
|
||||
options: [{
|
||||
name: 'user',
|
||||
description: 'The user to kiss',
|
||||
required: true,
|
||||
type: Constants.ApplicationCommandOptionTypes.USER
|
||||
}],
|
||||
|
||||
async execute (client, message, _, config) {
|
||||
const taggedUser = message.mentions.users.first();
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
const { Constants } = require('discord.js');
|
||||
|
||||
const gifchoices = [
|
||||
'https://cdn.discordapp.com/attachments/803658122299572255/805314244123951114/cef569820773b0f5d54ee34cfa18e1f8.gif',
|
||||
'https://cdn.lowgif.com/full/2027501b8fa5225c-.gif',
|
||||
|
@ -9,6 +11,12 @@ module.exports = {
|
|||
|
||||
name: require('path').parse(__filename).name,
|
||||
description: 'Licks a user!',
|
||||
options: [{
|
||||
name: 'user',
|
||||
description: 'The user to lick',
|
||||
required: true,
|
||||
type: Constants.ApplicationCommandOptionTypes.USER
|
||||
}],
|
||||
|
||||
async execute (client, message, _, config) {
|
||||
const taggedUser = message.mentions.users.first();
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
const { Constants } = require('discord.js');
|
||||
|
||||
const gifchoices = [
|
||||
'https://i.imgur.com/Ns1RBzX.gif',
|
||||
'https://cdn.lowgif.com/full/2027501b8fa5225c-.gif',
|
||||
|
@ -9,6 +11,12 @@ module.exports = {
|
|||
|
||||
name: require('path').parse(__filename).name,
|
||||
description: 'Noms an user!',
|
||||
options: [{
|
||||
name: 'user',
|
||||
description: 'The user to nom',
|
||||
required: true,
|
||||
type: Constants.ApplicationCommandOptionTypes.USER
|
||||
}],
|
||||
|
||||
async execute (client, message, _, config) {
|
||||
const taggedUser = message.mentions.users.first();
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
const { Constants } = require('discord.js');
|
||||
|
||||
const gifchoices = [
|
||||
'https://cdn.discordapp.com/attachments/803658122299572255/803708174293008474/tenor.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,
|
||||
description: 'Pats a user!',
|
||||
options: [{
|
||||
name: 'user',
|
||||
description: 'The user to pat',
|
||||
required: true,
|
||||
type: Constants.ApplicationCommandOptionTypes.USER
|
||||
}],
|
||||
|
||||
async execute (client, message, _, config) {
|
||||
const taggedUser = message.mentions.users.first();
|
||||
|
|
|
@ -2,6 +2,7 @@ module.exports = {
|
|||
|
||||
name: require('path').parse(__filename).name,
|
||||
description: 'Gets bot ping',
|
||||
options: [],
|
||||
|
||||
async execute (client, message, _, config) {
|
||||
const index = Math.floor(Math.random() * config.locations.length);
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
const { Constants } = require('discord.js');
|
||||
|
||||
const gifchoices = [
|
||||
'https://i.pinimg.com/originals/b4/95/fb/b495fb19f4b9a1b04f48297b676c497b.gif',
|
||||
'https://i.imgur.com/H7Ok5tn.gif',
|
||||
|
@ -8,6 +10,12 @@ module.exports = {
|
|||
|
||||
name: require('path').parse(__filename).name,
|
||||
description: 'Pokes a user!',
|
||||
options: [{
|
||||
name: 'user',
|
||||
description: 'The user to poke',
|
||||
required: true,
|
||||
type: Constants.ApplicationCommandOptionTypes.USER
|
||||
}],
|
||||
|
||||
async execute (client, message, _, config) {
|
||||
const taggedUser = message.mentions.users.first();
|
||||
|
|
|
@ -2,6 +2,7 @@ module.exports = {
|
|||
|
||||
name: require('path').parse(__filename).name,
|
||||
description: 'Reloads a command',
|
||||
options: [],
|
||||
|
||||
async execute (client, message, args, config) {
|
||||
const avatarURL = message.author.displayAvatarURL();
|
||||
|
|
|
@ -2,6 +2,7 @@ module.exports = {
|
|||
|
||||
name: require('path').parse(__filename).name,
|
||||
description: 'Restarts the bot',
|
||||
options: [],
|
||||
|
||||
async execute (client, message, _, config) {
|
||||
if (message.author.id === config.ownerID) {
|
||||
|
|
|
@ -1,7 +1,15 @@
|
|||
const { Constants } = require('discord.js');
|
||||
|
||||
module.exports = {
|
||||
|
||||
name: require('path').parse(__filename).name,
|
||||
description: 'Sets your nickname',
|
||||
options: [{
|
||||
name: 'name',
|
||||
description: 'The new nickname',
|
||||
required: true,
|
||||
type: Constants.ApplicationCommandOptionTypes.STRING
|
||||
}],
|
||||
|
||||
async execute (client, message, args, config) {
|
||||
const avatarURL = message.author.displayAvatarURL();
|
||||
|
|
|
@ -1,7 +1,15 @@
|
|||
const { Constants } = require('discord.js');
|
||||
|
||||
module.exports = {
|
||||
|
||||
name: require('path').parse(__filename).name,
|
||||
description: 'Slaps an user!',
|
||||
options: [{
|
||||
name: 'user',
|
||||
description: 'The user to slap',
|
||||
required: true,
|
||||
type: Constants.ApplicationCommandOptionTypes.USER
|
||||
}],
|
||||
|
||||
async execute (client, message, _, config) {
|
||||
const taggedUser = message.mentions.users.first();
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
const { Constants } = require('discord.js');
|
||||
|
||||
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/806775411928989726/snuggl1.gif',
|
||||
|
@ -8,6 +10,12 @@ module.exports = {
|
|||
|
||||
name: require('path').parse(__filename).name,
|
||||
description: 'Snuggle an user!',
|
||||
options: [{
|
||||
name: 'user',
|
||||
description: 'The user to snuggle',
|
||||
required: true,
|
||||
type: Constants.ApplicationCommandOptionTypes.USER
|
||||
}],
|
||||
|
||||
async execute (client, message, _, config) {
|
||||
const taggedUser = message.mentions.users.first();
|
||||
|
|
|
@ -2,6 +2,7 @@ module.exports = {
|
|||
|
||||
name: require('path').parse(__filename).name,
|
||||
description: "IT'S TIME TO STOP!... the bot",
|
||||
options: [],
|
||||
|
||||
async execute (_0, message, _1, config) {
|
||||
if (message.author.id === config.ownerID) {
|
||||
|
|
|
@ -1,8 +1,21 @@
|
|||
const { Constants } = require('discord.js');
|
||||
|
||||
module.exports = {
|
||||
|
||||
name: require('path').parse(__filename).name,
|
||||
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) {
|
||||
const user = message.mentions.users.first() || message.member;
|
||||
|
|
34
start.js
34
start.js
|
@ -5,14 +5,12 @@ const Discord = require('discord.js');
|
|||
const config = require('./config.json');
|
||||
console.log('Starting!');
|
||||
const client = new Discord.Client({ intents: config.intents.map(intent => eval(`Discord.Intents.FLAGS.${intent}`)) });
|
||||
|
||||
client.commands = new Discord.Collection();
|
||||
|
||||
const commandFiles = fs.readdirSync('./commands').filter(file => file.endsWith('.js'));
|
||||
|
||||
for (const file of commandFiles) {
|
||||
fs.readdirSync('./commands').filter(file => file.endsWith('.js')).forEach(file => {
|
||||
const command = require(`./commands/${file}`);
|
||||
client.commands.set(command.name, command);
|
||||
}
|
||||
});
|
||||
|
||||
client.generateErrorMessage = (errorMsg, avatarURL) => ({
|
||||
embeds: [{
|
||||
|
@ -33,8 +31,28 @@ client.generateErrorMessage = (errorMsg, avatarURL) => ({
|
|||
|
||||
client.on('error', (e) => console.log(`[ERROR] ${e}`));
|
||||
client.on('warn', (e) => (`[WARN] ${e}`));
|
||||
client.once('ready', () => {
|
||||
console.clear();
|
||||
client.once('ready', async () => {
|
||||
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(' / /| | / __ \\/ / __/ ___/ __ \\| |/_/');
|
||||
|
@ -62,7 +80,7 @@ client.on('messageCreate', async (message) => {
|
|||
try {
|
||||
await client.commands.get(command).execute(client, message, args, config);
|
||||
} catch (error) {
|
||||
console.stack();
|
||||
console.trace();
|
||||
message.channel.send({
|
||||
embeds: [{
|
||||
title: '<:AnitroxError:809651936563429416> **Something went wrong!**',
|
||||
|
|
Reference in New Issue