UnknownMessageCommandName event is not working

So i was making the event but when i run >pinewfweew for example or any other wrong command nothing appears in the console.
import type { UnknownMessageCommandNamePayload } from '@sapphire/framework';
import { Listener } from '@sapphire/framework';

export class UserEvent extends Listener {
public run(payload: UnknownMessageCommandNamePayload) {
console.log(payload)
}


}
import type { UnknownMessageCommandNamePayload } from '@sapphire/framework';
import { Listener } from '@sapphire/framework';

export class UserEvent extends Listener {
public run(payload: UnknownMessageCommandNamePayload) {
console.log(payload)
}


}
Solution:
Change the event to Events.UnknownMessageCommand. You'll need to add Events to your @sapphire/framework import
Jump to solution
27 Replies
Ben
Ben2y ago
You need to actually specify what even to listen to in the event option on the listener constructor. You can do that either by writing a constructor for your listener and calling super() inside of that or using the @ApplyOptions() decorator. You probably should read the guide on creating your own listeners: https://www.sapphirejs.dev/docs/Guide/listeners/creating-your-own-listeners
Sapphire Framework
Creating your own listeners | Sapphire
Similar to what you learned in both Creating Commands and [Creating
vphilip
vphilip2y ago
here is my new code and i am not getitng anything in the console when i run a wrong command
import type { UnknownMessageCommandNamePayload } from '@sapphire/framework';
import { Listener } from '@sapphire/framework';
import { ApplyOptions } from "@sapphire/decorators";


@ApplyOptions<Listener.Options>({
event: 'UnknownMessageCommandName'
})
export class UserEvent extends Listener {
public run(payload: UnknownMessageCommandNamePayload) {
console.log(payload)

}


}
import type { UnknownMessageCommandNamePayload } from '@sapphire/framework';
import { Listener } from '@sapphire/framework';
import { ApplyOptions } from "@sapphire/decorators";


@ApplyOptions<Listener.Options>({
event: 'UnknownMessageCommandName'
})
export class UserEvent extends Listener {
public run(payload: UnknownMessageCommandNamePayload) {
console.log(payload)

}


}
Ben
Ben2y ago
lowercase u in the event name
vphilip
vphilip2y ago
still the same thing
Ben
Ben2y ago
You can also use the Events export I linked in your last post so that you dont need to worry about spelling it wrong That would be Events.UnknownMessageCommand Do you have a prefix set, loadMessageCommandListeners set to true in the client options, and the message content intent?
vphilip
vphilip2y ago
yeah
Ben
Ben2y ago
Can you show your main or index file where you create the sapphire client?
vphilip
vphilip2y ago
Ben
Ben2y ago
Do you have the message content intent switch on in the dev portal
vphilip
vphilip2y ago
yep normal commands work fine
Ben
Ben2y ago
Can you check if the listener is loading in correctly by adding an onLoad() function that just logs something?
vphilip
vphilip2y ago
where can i add that
Ben
Ben2y ago
in the listener
vphilip
vphilip2y ago
alr and what shouldi put into it
Ben
Ben2y ago
Just log something so you can tell if it runs the onLoad function should run when the listener loads right after you start the bot. If that doesnt happen then we'll know that the listener isnt loading
vphilip
vphilip2y ago
that should work right?
Ben
Ben2y ago
no Keep the event the same, add a function to your listener class called onLoad
vphilip
vphilip2y ago
i dont understand so like delete that file?
Ben
Ben2y ago
Is the file in your most recent screenshot different from the one in the replied message?
vphilip
vphilip2y ago
wdym yes
Ben
Ben2y ago
Then yes, delete the onload file Wait can you send the unknown message command file again?
vphilip
vphilip2y ago
thats what its called
Ben
Ben2y ago
please send the contents of that file
vphilip
vphilip2y ago
import type { UnknownMessageCommandNamePayload } from '@sapphire/framework';
import { Listener } from '@sapphire/framework';
import { ApplyOptions } from "@sapphire/decorators";

@ApplyOptions<Listener.Options>({
event: 'unknownMessageCommandName'
})
export class UserEvent extends Listener {
public run(payload: UnknownMessageCommandNamePayload) {
console.log(payload)

}


}
import type { UnknownMessageCommandNamePayload } from '@sapphire/framework';
import { Listener } from '@sapphire/framework';
import { ApplyOptions } from "@sapphire/decorators";

@ApplyOptions<Listener.Options>({
event: 'unknownMessageCommandName'
})
export class UserEvent extends Listener {
public run(payload: UnknownMessageCommandNamePayload) {
console.log(payload)

}


}
Solution
Ben
Ben2y ago
Change the event to Events.UnknownMessageCommand. You'll need to add Events to your @sapphire/framework import
vphilip
vphilip2y ago
finally thank you so much sorry for wasting yout tme
Ben
Ben2y ago
Glad I could help