feat: removed ready message

This commit is contained in:
TresAbhi committed 2023-05-19 23:30:50 +00:00
1 parent 11365a6cd9
commit cd48b65ed6
5 files changed
+10 -25

No files matched your search

+42
View File
@@ -0,0 +1,42 @@
import { Client, EmbedBuilder, TextChannel } from 'discord.js';
import discord from '../../discord.json' assert { type: 'json' };
import { NEGATIVE_COLOR } from '../constants/colors.js';
import isDev from '../core/process/isDev.js';
import { client } from '../index.js';
const PROCESS_ERROR_EVENTS = ['uncaughtException'];
const CLIENT_ERROR_EVENTS = ['error'];
export function handleError(error: Error, client: Client, command: string) {
console.error(error);
(
client.guilds.cache
.get(discord.guild_id)
?.channels.cache.get(discord.log_channel) as TextChannel
).send({
embeds: [
new EmbedBuilder()
.setTitle(`${client.user?.username} ran into an error`)
.setColor(NEGATIVE_COLOR)
.setDescription(
`\`\`\`${[command, error.name, error.message, error.stack]
.filter((item) => item !== undefined)
.join('\n\n')}\`\`\``,
),
],
});
}
export function registerErrorHandlers() {
if (!isDev()) {
PROCESS_ERROR_EVENTS.forEach((name) =>
process.on(name, (error) => handleError(error, client, 'process error')),
);
CLIENT_ERROR_EVENTS.forEach((name) =>
client.on(name, (error) => handleError(error, client, 'client error')),
);
}
return client;
}
+23
View File
@@ -0,0 +1,23 @@
import { EmbedBuilder, GuildMember, TextChannel } from 'discord.js';
import discord from '../../discord.json' assert { type: 'json' };
import { SKILLED_COLOR } from '../constants/colors.js';
export default async function (member: GuildMember) {
if (member.guild.id === discord.guild_id) {
await (
member.guild.channels.cache.get(discord.verify_channel) as TextChannel
).send({
content: member.toString(),
embeds: [
new EmbedBuilder()
.setColor(SKILLED_COLOR)
.setTitle(`Welcome ${member.user.username}`)
.setDescription(
`Welcome to the Skilled server, **${member.user.username}**! To continue, please use the \`/verify\` command.\n\nExample: \`/verify Europe Sabina244\``,
),
],
});
console.log(`${member.user.tag} joined`);
}
}
+115
View File
@@ -0,0 +1,115 @@
import {
AutocompleteInteraction,
CacheType,
ChatInputCommandInteraction,
Collection,
Interaction,
REST,
RESTPostAPIChatInputApplicationCommandsJSONBody,
Routes,
SlashCommandBuilder,
} from 'discord.js';
import { readdirSync } from 'fs';
import discord from '../../discord.json' assert { type: 'json' };
import { args } from '../core/process/args.js';
import getClientId from '../core/process/getClientId.js';
import isDev from '../core/process/isDev.js';
export interface CommandRegistry {
inDevelopment: boolean; // register with Skilled Bot (default: false)
inProduction: boolean; // register with Skilled Canary (default: false)
inPublic: boolean; // registers on all servers (default: true)
command: Omit<SlashCommandBuilder, 'addSubcommand' | 'addSubcommandGroup'>;
execute: (interaction: ChatInputCommandInteraction<CacheType>) => void;
autocomplete?: (interaction: AutocompleteInteraction<CacheType>) => void;
}
const rest = new REST().setToken(args['discord-token']);
const commandFolders = readdirSync('src/commands/');
const commandCollection = new Collection<string, CommandRegistry>();
export const guildCommands: RESTPostAPIChatInputApplicationCommandsJSONBody[] =
[];
export const publicCommands: RESTPostAPIChatInputApplicationCommandsJSONBody[] =
[];
for (const file of commandFolders) {
const command = (await import(`../commands/${file}`))
.default as CommandRegistry;
if (isDev() ? command.inDevelopment : command.inProduction) {
if (command.inPublic) {
publicCommands.push(command.command.toJSON());
} else {
guildCommands.push(command.command.toJSON());
}
commandCollection.set(command.command.name, command);
}
}
try {
console.log(`Refreshing ${publicCommands.length} public command(s).`);
const publicData = (await rest.put(
Routes.applicationCommands(getClientId()),
{ body: publicCommands },
)) as RESTPostAPIChatInputApplicationCommandsJSONBody[];
console.log(`Successfully refreshed ${publicData.length} public command(s).`);
console.log(`Refreshing ${guildCommands.length} guild command(s).`);
const guildData = (await rest.put(
Routes.applicationGuildCommands(getClientId(), discord.guild_id),
{ body: guildCommands },
)) as RESTPostAPIChatInputApplicationCommandsJSONBody[];
console.log(`Successfully refreshed ${guildData.length} guild command(s).`);
} catch (error) {
console.error(error);
}
export default async function interactionCreate(
interaction: Interaction<CacheType>,
) {
if (interaction.isAutocomplete()) {
const command = commandCollection.get(interaction.commandName);
if (!command) {
console.error(
`No command matching ${interaction.commandName} was found.`,
);
return;
}
try {
if (command.autocomplete) command.autocomplete(interaction);
} catch (error) {
console.error(error);
}
} else if (interaction.isChatInputCommand()) {
const command = commandCollection.get(interaction.commandName);
if (!command) {
console.error(
`No command matching ${interaction.commandName} was found.`,
);
return;
}
try {
await interaction.deferReply();
command.execute(interaction);
} catch (error) {
console.error(error);
if (interaction.replied || interaction.deferred) {
await interaction.followUp({
content: 'There was an error while executing this command!',
ephemeral: true,
});
} else {
await interaction.editReply({
content: 'There was an error while executing this command!',
});
}
}
}
}
+10
View File
@@ -0,0 +1,10 @@
import { Client } from 'discord.js';
import isDev from '../core/process/isDev.js';
export default function ready(client: Client<true>) {
console.log(
`Logged in as ${client.user.tag} in ${
isDev() ? 'development' : 'production'
} mode`,
);
}