0

So I am usually used to slapping the code in a singular spaghetti-o index.js file, yet this time I have two folders:

One for commands

One for events

While the main index.js is only with listeners for the above two in order to execute events and commands.

I am trying to get a messageCreate event trigger in a messageCreate.js within the events folder, I messed around with the intents on both the index.js and messageCreate.js event file, yet nothing seem to go through unless I did something wrong.

Here's what I am trying to do:

const { Events } = require('discord.js');


module.exports = {
    name: Events.MessageCreate,
    async execute(messageCreate) {
            if(message.content == "Give me a random phrase for no reason!") {
              var ran = [("A"),
                ("Some"),
                ("Ah"),
                ("You"),
                ("They"),
                ("He"),
                ("She"),
                ("Was"),
                ("Were"),
                ("Weren't"),
                ("Were you"),
                ("Weren't you"),
                ("Are you"),
                ("Aren't you"),

No need to pay attention to the rest of the code, what it does is basically simple. Grabs three variables, mashes them together and outputs a random spaghetti of words, yet whenever the trigger message is sent within the server, the code does not execute whatsoever and there is no error message either.

I tried putting it into the main index.js file to see if it would do anything different, and nothing seem to work out.

Here are the intents in the index.js file, which I tried copying into the messageCreate.js event file as well with no success:

const { Client, Collection, Events, GatewayIntentBits, GuildMessages, DirectMessages } = require('discord.js');

How can I get the messageCreate.js to be executed once the trigger message is sent?

  • Does this answer your question? [message.content doesn't have any value in Discord.js](https://stackoverflow.com/questions/73036854/message-content-doesnt-have-any-value-in-discord-js) – Zsolt Meszaros Dec 02 '22 at 16:48
  • Not really, I've already tried the GuildMessages intent as well and others listed to no avail. Though I'll give it another go in a few hours – Flying Kart Dec 02 '22 at 21:28
  • If you tried to import it as you mentioned above (i.e. `{ GuildMessages, DirectMessages } = require('discord.js');` then it won't work. – Zsolt Meszaros Dec 02 '22 at 23:02
  • In the main index.js I put in the ```GatewayIntentBits.MessageContent,``` and ```GatewayIntentBits.GuildMessages,```, following exactly how its written there. On the main index.js file works, however on the event file messageCreate.js within the "events" folder, it doesn't after copying and pasting the same code into both files and testing them. Do I have to do something like ``const client = new Client`` in order to get it to work? – Flying Kart Dec 03 '22 at 03:12

1 Answers1

0

Got it to work.

In the main index.js file, simply do this:

const client = new Client({ intents: [
    GatewayIntentBits.Guilds,
    GatewayIntentBits.MessageContent,
    GatewayIntentBits.GuildMessages,
    ],
    partials: [Partials.Channel],
 });

Then in the messageCreate.js file within the "events" folder, I did this:

const { Events, MessageContent, client } = require('discord.js');


module.exports = {
    name: Events.MessageCreate,
    async execute(message) {
            if(message.content == "Give me a random phrase for no reason!") {
              var ran = [("A"),
                ("Some"),
                ("Ah"),
                ("You"),
                ("They"),
                ("He"),
                ("She"),
                ("Was"),