Should my bot sending out dm's trigger it's own messageCreate event?

All of a sudden my bot is registering it's own messages as events
12 Replies
24
24ā€¢2y ago
Are you using sapphire or your own command framework?
Acier
Acierā€¢2y ago
Sapphire
24
24ā€¢2y ago
sapphire should ignore bots by default
Acier
Acierā€¢2y ago
Alright, let me share code
export class MessageCreateListener extends Listener
{
public constructor(context: Listener.Context, options: Listener.Options)
{
super(context, {
...options,
once: false,
event: 'messageCreate'
});
}

public async run(message: Message)
{
// @ts-ignore
if (message.partial) message = await message.fetch().catch(() => {});

if (message.content == 'ping')
await message.reply('pong')

MessageManager.onMessage(message).then(() => {});
}
export class MessageCreateListener extends Listener
{
public constructor(context: Listener.Context, options: Listener.Options)
{
super(context, {
...options,
once: false,
event: 'messageCreate'
});
}

public async run(message: Message)
{
// @ts-ignore
if (message.partial) message = await message.fetch().catch(() => {});

if (message.content == 'ping')
await message.reply('pong')

MessageManager.onMessage(message).then(() => {});
}
24
24ā€¢2y ago
I'm curious on what this code is supposed to do
Acier
Acierā€¢2y ago
export class MessageManager
{
public static async onMessage(message: Message) {
if (message.channel.type == "DM" && message.content) {
console.log(message.content)
console.log(message.author)
// Send a reaction
await message.react('āœ…')
}
}
}
export class MessageManager
{
public static async onMessage(message: Message) {
if (message.channel.type == "DM" && message.content) {
console.log(message.content)
console.log(message.author)
// Send a reaction
await message.react('āœ…')
}
}
}
24
24ā€¢2y ago
also no, then sapphire won't ignore bots because you're using your own listener you're literally listening to message events, as emitted by djs and NOT sapphire so without the preprocesssing of sapphire yeah you will get bot messages because your code doesn't filter them also the message = await message.fetch() is odd you can just do if partial { await message.fetch() } nonetheless, weird implementation. What is your goal with this code?
Acier
Acierā€¢2y ago
I cut out all the actual implementation, it's meant to forward the bot's dm's to log channels, but I cut all that out
24
24ā€¢2y ago
forward bot dms to log channels? šŸ˜¬ there's an event that you can listen to instead of messageCreate that can run after sapphire parses it so you get the benefit of partial-free and bot-free message
Acier
Acierā€¢2y ago
Would love that, is it in the guide? I thought the standard djs events were already pre-parsed
24
24ā€¢2y ago
No description
24
24ā€¢2y ago
sapphire does not modify any djs event it merely builds on top of them PreMessageCommandRun seems like the one you want or PrefixedMessage the latter more useful I also suggest removing your MessageManager static class to be inlined into the listener because the manager class does nothing more than some reactions it looks
Want results from more Discord servers?
Add your server