feat: command arguments

This commit is contained in:
TresAbhi committed 2023-04-19 00:26:51 +00:00
1 parent b84ef0cebf
commit 363f110c2f
6 files changed
+191 -25

No files matched your search

-9
View File
@@ -1,9 +0,0 @@
import { SlashCommandBuilder } from 'discord.js';
export const data = new SlashCommandBuilder()
.setName('verify')
.setDescription('Verifies the user with Blitz');
export async function execute(interaction) {
await interaction.reply('uwu i done nothin here uwu');
}
+34
View File
@@ -0,0 +1,34 @@
import { CommandInteraction, SlashCommandBuilder } from 'discord.js';
export function execute(interaction: CommandInteraction) {
interaction.reply(
//@ts-ignore
`you said your blitz username was ${interaction.options.getString(
'ign',
)} in ${
//@ts-ignore
interaction.options.getString('server')
}`,
);
}
export const data = new SlashCommandBuilder()
.setName('verify')
.setDescription('Verifies the user with Blitz')
.addStringOption((option) =>
option
.setName('server')
.setDescription('The Blitz server you are in')
.setRequired(true)
.addChoices(
{ name: 'NA', value: 'na' },
{ name: 'EU', value: 'eu' },
{ name: 'ASIA', value: 'asia' },
),
)
.addStringOption((option) =>
option
.setName('ign')
.setDescription('The username you use in Blitz')
.setRequired(true),
);
+29 -13
View File
@@ -4,8 +4,10 @@ import {
Collection,
EmbedBuilder,
GatewayIntentBits,
Interaction,
REST,
Routes,
SlashCommandBuilder,
} from 'discord.js';
import { readdirSync } from 'fs';
import config from '../config.json' assert { type: 'json' };
@@ -19,27 +21,38 @@ client.on('ready', (c) => {
console.log(`Logged in as ${c.user.tag}!`);
});
client.on('guildMemberAdd', (member) => {
member.guild.channels.cache.get(config.verifyChannel)?.send({
client.on('guildMemberAdd', async (member) => {
//@ts-ignore
await member.guild.channels.cache.get(config.discord_verify_channel)?.send({
embeds: [
new EmbedBuilder()
.setColor('#8e3cf5')
.setTitle(`Welcome ${member.user.username}`)
.setDescription(
`Welcome to the Skilled server, ${member.toString()}! To continue, please use the \`/verify\` command.\n\nExample: \`/verify ${faker.name.firstName()}${faker.datatype.number(
`Welcome to the Skilled server, **${
member.user.username
}**! To continue, please use the \`/verify\` command.\n\nExample: \`/verify NA ${faker.name.firstName()}${faker.datatype.number(
{ min: 1, max: 100 },
)}\``,
),
],
});
await member.guild.channels.cache
.get(config.discord_verify_channel)
//@ts-ignore
?.send(member.toString());
});
client.commands = new Collection();
export interface CommandRegistry {
data: SlashCommandBuilder;
execute: (interaction: Interaction) => void;
}
client.on('interactionCreate', async (interaction) => {
const commandCollection = new Collection<string, CommandRegistry>();
client.on('interactionCreate', async (interaction: Interaction) => {
if (!interaction.isChatInputCommand()) return;
const command = interaction.client.commands.get(interaction.commandName);
const command = commandCollection.get(interaction.commandName);
if (!command) {
console.error(`No command matching ${interaction.commandName} was found.`);
@@ -71,23 +84,26 @@ const commandFolders = readdirSync(foldersPath);
for (const file of commandFolders) {
const command = await import(`./commands/${file}`);
commands.push(command.data.toJSON());
client.commands.set(command.data.name, command);
commandCollection.set(command.data.name, command);
}
// Construct and prepare an instance of the REST module
const rest = new REST().setToken(config.token);
const rest = new REST().setToken(config.discord_token);
try {
console.log(`Started refreshing ${commands.length} command(s).`);
const data = await rest.put(
Routes.applicationGuildCommands(config.clientId, config.guildId),
const data = (await rest.put(
Routes.applicationGuildCommands(
config.discord_client_id,
config.discord_guild_id,
),
{ body: commands },
);
)) as { length: number };
console.log(`Successfully reloaded ${data.length} command(s).`);
} catch (error) {
console.error(error);
}
client.login(config.token);
client.login(config.discord_token);