#messageCreate event (help system)

73 messages · Page 1 of 1 (latest)

tired ledge
#
const { EmbedBuilder, ChannelType } = require('discord.js');

module.exports = {
    name: 'messageCreate',
    on: true,
    execute(channel, message){
        console.log('Message')
        if(message.content.includes('@Yara')) return true;
        if(channel.type !== ChannelType.DM) return;
            const whatTypeHelpEmbed = new EmbedBuilder()
            .setColor('Red')
            .setTitle('Hello!')
            .setDescription('Please select one of the options below.\n\n> 1️⃣ - I have a question about something.\n> 2️⃣ - I have a complaint about an issue.')
            message.author.send({ embeds: [whatTypeHelpEmbed]}).then(() => {
                whatTypeHelpEmbed.react('1️⃣')
                whatTypeHelpEmbed.react('2️⃣')
            })
    }
}

Output Nothing
Please help, i do have the special thing turned on in dev and i have message content gateway bits

nimble shellBOT
#

• What's your exact discord.js npm list discord.js and node node -v version?
• Post the full error stack trace, not just the top part!
• Show your code!
• Explain what exactly your issue is.
• Not a discord.js issue? Check out #useful-servers.

tired ledge
#

no output in DMs

#

output in channels on server

#

nevermind i got it working

#

nevermind

#

i will get a message in dm from bot if i send a message in the server, but i can send any message and not @Yara but i cant get a message if i send something in dms

humble sedge
#

@tired ledge

tired ledge
#

ye

humble sedge
#

You do realize, if the bot is pinged, or you type @Yara it returns?

tired ledge
#

ye, returns true

humble sedge
#

yeah

#

So it returns the process

#

And doesn't do anything

tired ledge
#

when i put if like this if(message.content.includes('@Yara')){ nothing happens

humble sedge
#

Remove the line.....

#

There's your fix

#

Or

#

Instead of

#

@Yara

#

Do .includes("Bot ID")

#

like

#

.includes("709960501378940939")

reef flame
#

I reckon you have been bamboozled by the message content privilaged intent

tired ledge
#

'Please help, i do have the special thing turned on in dev and i have message content gateway bits"

#

so no

#

because i have it on

twilit socket
#

Where and how do you call that file?

tired ledge
#
const eventsPath = path.join(__dirname, 'Events');const eventFiles = fs.readdirSync(eventsPath).filter(file => file.endsWith('.js'));for (const file of eventFiles) {    const event_filePath = path.join(eventsPath, file);    const event = require(event_filePath);    if (event.once) {        client.once(event.name, (...args) => event.execute(...args));    } else {        client.on(event.name, (...args) => event.execute(...args));    }}
twilit socket
#

Okay, messageCreate event only has one parameter, the message. Your function expects two parameters. So channel will actually be a Message and message will be undefined

#

No idea how that wouldn’t throw errors for you

tired ledge
#
const { EmbedBuilder, ChannelType } = require('discord.js');module.exports = {    name: 'messageCreate',    on: true,    async execute(message, channel){        console.log('Message')        if(!channel.type === ChannelType.DM) return;        console.log(channel.type === ChannelType.DM)        if(message.content === process.env.CLIENT_ID){            const whatTypeHelpEmbed = new EmbedBuilder()            .setColor('Red')            .setTitle('Hello!')            .setDescription('Please select one of the options below.\n\n> 1️⃣ - I have a question about something.\n> 2️⃣ - I have a complaint about an issue.')            const messageEmbed = await message.author.send({ embeds: [whatTypeHelpEmbed]})            messageEmbed.react('1️⃣')            messageEmbed.react('2️⃣')        }    }}
#

error

#
Message
node:events:368
      throw er; // Unhandled 'error' event
      ^

TypeError: Cannot read properties of undefined (reading 'type')
    at Object.execute (/Volumes/SEB'S USB/Yara Bot/Events/helpSystem.js:8:21)
    at Client.<anonymous> (/Volumes/SEB'S USB/Yara Bot/index.js:48:44)
    at Client.emit (node:events:390:28)
    at MessageCreateAction.handle (/Volumes/SEB'S USB/Yara Bot/node_modules/discord.js/src/client/actions/MessageCreate.js:23:14)
    at Object.module.exports [as MESSAGE_CREATE] (/Volumes/SEB'S USB/Yara Bot/node_modules/discord.js/src/client/websocket/handlers/MESSAGE_CREATE.js:4:32)
    at WebSocketManager.handlePacket (/Volumes/SEB'S USB/Yara Bot/node_modules/discord.js/src/client/websocket/WebSocketManager.js:352:31)
    at WebSocketShard.onPacket (/Volumes/SEB'S USB/Yara Bot/node_modules/discord.js/src/client/websocket/WebSocketShard.js:481:22)
    at WebSocketShard.onMessage (/Volumes/SEB'S USB/Yara Bot/node_modules/discord.js/src/client/websocket/WebSocketShard.js:321:10)
    at WebSocket.onMessage (/Volumes/SEB'S USB/Yara Bot/node_modules/ws/lib/event-target.js:199:18)
    at WebSocket.emit (node:events:390:28)
Emitted 'error' event on Client instance at:
    at emitUnhandledRejectionOrErr (node:events:251:10)
    at processTicksAndRejections (node:internal/process/task_queues:85:21)
tired ledge
#

i sawpped message and channel tho

twilit socket
#

Read the sixth word in my answer.

#

Maybe fourth to seventh to really get it

tired ledge
#

so how do i get channel to work

twilit socket
#

message.channel

tired ledge
#

k

#

now it works but it the file wont run if i type in dms

tired ledge
#

or is it just messageCreate

twilit socket
#

Do you have DirectMessages intent and Channel partial?

tired ledge
#

DM no

#

now i do

tired ledge
twilit socket
#

The code is wrong. console.log(message.content) and check for yourself

tired ledge
#

output <@ID>

#

ID is bot id

#

it works

#

yayayayayayayayayay

#

🎉

#

how do i get reactions to work

const filter = (reaction, user) => {                return ['1️⃣', '2️⃣'].includes(reaction.emoji.name) && user.id === message.author.id;            };                        messageEmbed.awaitReactions({ filter, max: 1, time: 60000, errors: ['time'] })                .then(collected => {                    const reaction = collected.first();                                if (reaction.emoji.name === '1️⃣') {                        messageEmbed.reply('You reacted with a thumbs up.');                    } else {                        messageEmbed.reply('You reacted with a thumbs down.');                    }                })                .catch(collected => {                    message.reply('You reacted with neither a thumbs up, nor a thumbs down.');                });
#

after 60 sec, the message is sent

#

but when i. react to the message, the other message -> You reacted with a thumbs up. or the other doesnt send

nimble shellBOT
twilit socket
#

GuildMessageReactions intent?

tired ledge
#

yup i have it

tired ledge
twilit socket
#

Of course?

nimble shellBOT
twilit socket
#

The whole guide is up-to-Date

tired ledge
#

and not work

#
const { EmbedBuilder, ChannelType } = require('discord.js');module.exports = {    name: 'messageCreate',    on: true,    async execute(message){        console.log('Message')        console.log(message.content)        if(message.content === '<@ID>' && message.channel.type === ChannelType.DM){            const whatTypeHelpEmbed = new EmbedBuilder()            .setColor('Red')            .setTitle('Hello!')            .setDescription('Please select one of the options below.\n\n> 1️⃣ - I have a question about something.\n> 2️⃣ - I have a complaint about an issue.')            const messageEmbed = await message.author.send({ embeds: [whatTypeHelpEmbed]})            messageEmbed.react('1️⃣')            messageEmbed.react('2️⃣')            const filter = (reaction, user) => {                return ['1️⃣', '2️⃣'].includes(reaction.emoji.name) && user.id === message.author.id;            };            messageEmbed.awaitReactions({ filter, max: 1, time: 60000, errors: ['time'] })                .then(collected => {                    const reaction = collected.first();                                if (reaction.emoji.name === '1️⃣') {                        messageEmbed.reply('You reacted with a thumbs up.');                    } else {                        messageEmbed.reply('You reacted with a thumbs down.');                    }                })                .catch(collected => {                    message.reply('You reacted with neither a thumbs up, nor a thumbs down.');                });        }    }}
twilit socket
#

In DMs you‘d need DirectMessageReactions intent. Got that?

tired ledge
#

right 🤦

#

it works

#

i just really dumb

#

what is GatewayIntentBits.DirectMessageTyping

twilit socket
#

The indicator you see in DMs when the other person is typing. You probably won’t need that