#Parsing message error

1 messages · Page 1 of 1 (latest)

snow summit
#

@sleek notch

sleek notch
#

hi

snow summit
#

what was the issue you found?

sleek notch
#

i think i found the problem i didnt require my command handler

snow summit
#

well that might do it. is it logging your message now?

#

console.log(message)*

sleek notch
#

no

snow summit
#

ok. could you possibly send your two files (index.js and your first one you had issues with)

sleek notch
#

ok

snow summit
#

thanks

#

ok so it looks like you don't have a message event that triggers whenever a message is sent in a text channel

#

so parsing const message = require('...) don't do anything when it is logged

sleek notch
#

ok

#

wait in main or messagecreate

#

Identifier 'message' has already been declared

snow summit
#

i personally have my message handler in index.js and then parse the message variable into other files from there

#

you need to add that event and then do what you want with the message value from there

#
client.on('messageCreate', (message) => {
  console.log(message);
  // Whatever else you need to do
});
#

from within this event scope, you can then export it to another file (such as your messageCreate.js file, or you can handle the messageCreate event from within your messageCreate.ts file. you just need to parse in client if you want to do that)

sleek notch
#

it says client.on is not a function

snow summit
#

are you in index.js?

sleek notch
#

no

snow summit
#

you need to parse client into your messageCreate.js file if you want to use client.on

#

otherwise, you can just use client.on from within index.js

sleek notch
#

but i parsed it alrdy

snow summit
#

where did you parse client?

sleek notch
#

parameters

snow summit
#

i don't see it getting exported to your other file. can you please show where you make it an export and then require it in messageCreate.js?

sleek notch
#

const { Client, Message, MessageEmbed } = require("discord.js");

#

/**
*

  • @param {Client} client
  • @param {Message} message
    */
    async execute(client, message, Discord) {
snow summit
#

this isn't an issue with discord.js, rather it's fundamental knowledge with JavaScript

#

you need to export const client = ..., not import it from discord.js

sleek notch
#

oh so i need to do const client = require("../../main.js")

snow summit
#

yes, and export it from index.js

#

if you do that, you will be able to use client.on('messageCreate', () => { in your file