#Parsing message error
1 messages · Page 1 of 1 (latest)
hi
what was the issue you found?
i think i found the problem i didnt require my command handler
no
ok. could you possibly send your two files (index.js and your first one you had issues with)
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
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)
it says client.on is not a function
are you in index.js?
no
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
but i parsed it alrdy
where did you parse client?
parameters
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?
const { Client, Message, MessageEmbed } = require("discord.js");
/**
*
- @param {Client} client
- @param {Message} message
*/
async execute(client, message, Discord) {
ok right. that is importing the client constructor, not your actual client you constructed at the start of index.js
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
oh so i need to do const client = require("../../main.js")