Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

430
Views
discord.js guildCreate and guildDelete not firing

I am using discord.js to create a bot and have been following their guide until now to create the command and event handlers, including their format of putting each event handler and command function in its own file with its own exported module. This has worked fine for the 'ready' and 'interactionCreate' events, but for some reason my 'guildCreate' and 'guildDelete' events do not seem to be doing anything.

Here is how I am setting up the event listeners:

const eventsPath = path.join(__dirname, 'events');
const eventFiles = fs
    .readdirSync(eventsPath)
    .filter((file) => file.endsWith('.js'));

eventFiles.forEach((file) => {
    const filePath = path.join(eventsPath, file);
    const event = require(filePath);
    if (event.once) {
        client.once(event.name, (...args) => event.execute(...args));
    } else {
        client.on(event.name, (...args) => event.execute(...args));
    }
});

Here is the contents of guildCreate.js (guildDelete.js is the same except the name of the event is 'guildDelete'):

module.exports = {
    name: 'guildCreate',
    execute(guild) {
        console.log('joined guild');
        console.log(guild.name);
    },
};

I'm not sure why this is not printing anything as I can't see how it differs from the way the ready event is handled in the guide and that is working fine for me (https://discordjs.guide/creating-your-bot/event-handling.html#individual-event-files).

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Turns out that setting the intents to be 8 (the administrator permissions as calculated using the bit math calculator in the Discord Developer Portal) does not include access to guild events and I had to specifically set Intents.Flags.GUILDS

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!