Bugfix to slash commands

This commit is contained in:
Erik 2023-12-05 21:41:24 +02:00
parent c860861d27
commit b36ec44bb2
7 changed files with 20 additions and 23 deletions

View File

@ -239,7 +239,6 @@ class DiscordClient extends Client
this.#built = true;
this.emit('built');
return this;
}
async destroy ()

View File

@ -35,9 +35,10 @@ class Intercom
throw new Error('Missing client application');
const clientId = this.#client.application.id;
const commands = this.#client.registry
.filter<SlashCommand>((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 });

View File

@ -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;

View File

@ -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);

View File

@ -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;

View File

@ -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);
}

View File

@ -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;