export const bot = new Client({
// To use only guild command
// botGuilds: [(client) => client.guilds.cache.map((guild) => guild.id)],
// Discord intents
intents: [
IntentsBitField.Flags.Guilds,
IntentsBitField.Flags.GuildMembers,
IntentsBitField.Flags.GuildMessages,
IntentsBitField.Flags.GuildMessageReactions,
IntentsBitField.Flags.GuildVoiceStates,
],
guards: [NotBot],
// Debug logs are disabled in silent mode
silent: false,
// Configuration for @SimpleCommand
simpleCommand: {
prefix: "!",
},
});
event.ts
import { ArgsOf, Client, Once } from "discordx";
import { Discord, On } from "discordx";
@Discord()
export class Example {
@Once()
ready(client: Client): void {
console.log("Client Ready");
}
}
Package
@discordx/utilities
Version
Stable
Relevant log output
TypeError: Cannot read properties of undefined (reading 'author')
at NotBot (node_modules/@discordx/utilities/src/guards/NotBot/index.ts:60:24)
at next (node_modules/discordx/src/decorators/classes/Method.ts:94:63)
at node_modules/discordx/src/decorators/classes/Method.ts:108:31
at DOn.<anonymous> (node_modules/discordx/src/decorators/classes/Method.ts:40:49)
at node_modules/discordx/src/logic/metadata/MetadataStorage.ts:609:32
at Array.map (<anonymous>)
at Client.<anonymous> (node_modules/discordx/src/logic/metadata/MetadataStorage.ts:604:25)
at Object.onceWrapper (node:events:628:26)
at Client.emit (node:events:513:28)
at Client.emit (node:domain:489:12)
Code of Conduct
[X] I agree to follow this project's Code of Conduct
What happened?
I decided to use
NotBot
as a global guard during my refactor.When using decorators
Once
orOn
as the event handler for client ready, the emitter sends out a webhook event, not a user event.This causes an error.
The error does not exist for client.once or client.on ready events.
Fix
https://github.com/discordx-ts/discordx/blob/770703c33af9cd135afb47d828cf595f1b148365/packages/utilities/src/guards/NotBot/index.ts#L60
Allow user to be undefined.
Reproduction
I wont redo the whole code but simply:
main.ts
event.ts
Package
@discordx/utilities
Version
Stable
Relevant log output
Code of Conduct