diff --git a/src/client/DiscordClient.ts b/src/client/DiscordClient.ts index ca44fce..37a41da 100644 --- a/src/client/DiscordClient.ts +++ b/src/client/DiscordClient.ts @@ -239,7 +239,6 @@ class DiscordClient extends Client this.#built = true; this.emit('built'); return this; - } async destroy () diff --git a/src/client/components/Intercom.ts b/src/client/components/Intercom.ts index 1d2b0e9..299226e 100644 --- a/src/client/components/Intercom.ts +++ b/src/client/components/Intercom.ts @@ -35,9 +35,10 @@ class Intercom throw new Error('Missing client application'); const clientId = this.#client.application.id; const commands = this.#client.registry - .filter((c: SlashCommand) => c.type === 'command' && c.slash) + .filter((c: SlashCommand) => c.type === 'command' && c.slash) .map((c) => c.shape); + // console.log(inspect(commands, { depth: 25 })); if (process.env.NODE_ENV === 'development') return this.send('commands', { type: 'guild', commands, clientId }); diff --git a/src/client/components/observers/Automoderation.ts b/src/client/components/observers/Automoderation.ts index 25513ec..f850e6c 100644 --- a/src/client/components/observers/Automoderation.ts +++ b/src/client/components/observers/Automoderation.ts @@ -142,12 +142,14 @@ export default class AutoModeration extends Observer implements Initialisable { const { guildWrapper: guild, author } = message; let channel = message.channel as TextChannel; - const member = await guild.memberWrapper(message.author); if (channel.partial) channel = await channel.fetch(); - if (!guild || author.bot || message.filtered || !member) + if (!guild || author.bot || message.filtered) return; + const member = await guild.memberWrapper(message.author); + if (!member) + return; const settings = await guild.settings(); const { wordfilter: setting } = settings; const { bypass, ignore, enabled, silent, explicit, fuzzy, regex, whitelist, actions } = setting; diff --git a/src/client/components/wrappers/GuildWrapper.ts b/src/client/components/wrappers/GuildWrapper.ts index 7398bc2..efe3b27 100644 --- a/src/client/components/wrappers/GuildWrapper.ts +++ b/src/client/components/wrappers/GuildWrapper.ts @@ -504,11 +504,12 @@ class GuildWrapper async memberWrapper (user: UserResolveable) { const id = Util.hasId(user) ? user.id : user; - const member = await this.resolveMember(id); + const member = user instanceof GuildMember ? user : await this.resolveMember(id); if (!member) - return Promise.reject(new Error('No member found')); + // return Promise.reject(new Error('No member found')); + return null; if (this.#memberWrappers.has(member.id)) - return this.#memberWrappers.get(member.id); + return this.#memberWrappers.get(member.id)!; const wrapper = new MemberWrapper(this.#client, member, this); this.#memberWrappers.set(wrapper.id, wrapper); diff --git a/src/client/interfaces/commands/Command.ts b/src/client/interfaces/commands/Command.ts index c7b60e6..e2a6c69 100644 --- a/src/client/interfaces/commands/Command.ts +++ b/src/client/interfaces/commands/Command.ts @@ -365,7 +365,10 @@ abstract class Command extends Component } if (!(opt.name instanceof Array)) - this.#options.push(new CommandOption({ ...opt, client: this.client })); + { + this.#options.push(new CommandOption({ ...opt, client: this.client })); + continue; + } // Allows easy templating of subcommands that share arguments const { name: names, description, type, ...opts } = opt; diff --git a/src/middleware/Controller.ts b/src/middleware/Controller.ts index 6af73f5..621def9 100644 --- a/src/middleware/Controller.ts +++ b/src/middleware/Controller.ts @@ -2,7 +2,7 @@ import { EventEmitter } from 'node:events'; import { inspect } from 'node:util'; import path from 'node:path'; -import { IPCMessage } from '../../@types/Shared.js'; +import { CommandsDef, IPCMessage } from '../../@types/Shared.js'; import { BroadcastEvalOptions, ShardMethod, ShardingOptions } from '../../@types/Shard.js'; import { ControllerOptions } from '../../@types/Controller.js'; @@ -235,7 +235,7 @@ class Controller extends EventEmitter if (message._mEval) return this.eval(shard, { script: message._mEval, debug: message.debug || false }); if (message._commands) - return this.#slashCommandManager._handleMessage(message._commands); + return this.#slashCommandManager._handleMessage(message as CommandsDef); if (message._api) return this.apiRequest(shard, message); } diff --git a/src/middleware/rest/SlashCommandManager.ts b/src/middleware/rest/SlashCommandManager.ts index 8c83dc9..15070af 100644 --- a/src/middleware/rest/SlashCommandManager.ts +++ b/src/middleware/rest/SlashCommandManager.ts @@ -1,10 +1,3 @@ -// const { REST } = require('@discordjs/rest'); -// const { Routes } = require('discord-api-types/v9'); -// const fs = require('fs'); -// const path = require('path'); -// const hash = require('object-hash'); -// const { inspect } = require('util'); - import { REST } from '@discordjs/rest'; import { Routes } from 'discord-api-types/v9'; import hash from 'object-hash'; @@ -57,14 +50,11 @@ class SlashCommandManager async _handleMessage ({ commands, guilds, clientId, type }: CommandsDef) { - if (type === 'global') - { + fs.writeFileSync('./commands.json', JSON.stringify(commands, null, 4), { encoding: 'utf-8' }); + if (type === 'global') await this.#global(commands, clientId); - } - else if (type === 'guild') - { + else if (type === 'guild') await this.#guild(commands, { guilds, clientId }); - } } async #guild (commands: Command[], { guilds = [], clientId }: { guilds: string[], clientId: string }) @@ -126,6 +116,7 @@ class SlashCommandManager #parseError (error: ClusterFuck, commands: Command[]) { + // console.log(inspect(error, { depth: 25 })); this.#client.logger.error(`An issue has occured while updating guild commands. Guild command refresh aborted.\n${error.stack || error}`); // Figures out which command and option ran into issues const invalid = error.rawError.errors;