fetching scheduled events

Im having trouble figuring out how to fetch the scheduled events for a guild using. djs ver: 14.14.1 node ver 20.11.0 code is too long to include in this message see below i keep getting this error C:\Users\Robyn\source\repos\GodOfSandwiches\TauntBot>node index.js Ready! Logged in as PF Taunts#1988 Connected to MongoDB Atlas Connected to MongoDB Atlas Error fetching events for guild: 1095815129905504306 TypeError: GuildScheduledEvent.fetchEvents is not a function at getGuildEvents (C:\Users\Robyn\source\repos\GodOfSandwiches\TauntBot\guildEventManager.js:9:57) at scanForEvents (C:\Users\Robyn\source\repos\GodOfSandwiches\TauntBot\guildEventManager.js:21:37) at runEventShitIDK (C:\Users\Robyn\source\repos\GodOfSandwiches\TauntBot\index.js:45:5) at process.processTicksAndRejections (node:internal/process/task_queues:95:5) Error fetching events for guild: 1102982168243880019 TypeError: GuildScheduledEvent.fetchEvents is not a function at getGuildEvents (C:\Users\Robyn\source\repos\GodOfSandwiches\TauntBot\guildEventManager.js:9:57) at scanForEvents (C:\Users\Robyn\source\repos\GodOfSandwiches\TauntBot\guildEventManager.js:21:37) at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
7 Replies
d.js toolkit
d.js toolkit10mo ago
- What's your exact discord.js npm list discord.js and node node -v version? - Not a discord.js issue? Check out #other-js-ts. - Consider reading #how-to-get-help to improve your question! - Explain what exactly your issue is. - Post the full error stack trace, not just the top part! - Show your code! - Issue solved? Press the button!
GodOfSandwiches
GodOfSandwichesOP10mo ago
code: async function getGuildEvents(guild) { try { const events = await GuildScheduledEvent.fetchEvents(guild); // Fetch events for the guild return events; } catch (error) { console.error('Error fetching events for guild:', guild.id, error); return null; } } async function scanForEvents(client, dbClient) { // Scan events for all guilds the bot is in try { for (const guild of client.guilds.cache.values()) { let guildEvents = await getGuildEvents(guild); // Convert guildEvents to an array if it's not already if (!Array.isArray(guildEvents)) { guildEvents = [guildEvents]; } for (const event of guildEvents) { await processEvent(event); } } } catch (error) { console.error('Error scanning guilds and database for events:', error); } // Scan events from the database try { const db = dbClient.db('DiscordBot'); const eventsCollection = db.collection('events'); const dbEvents = await eventsCollection.find({}).toArray(); console.log('Events in database:', dbEvents); } catch (error) { console.error('Error scanning database for events:', error); } } code cont: async function processEvent(event, dbClient) { try { const db = dbClient.db('DiscordBot'); const eventsCollection = db.collection('events'); const currentTime = new Date(); const eventTime = new Date(event.scheduledStartAt); const eventData = { id: event.id, name: event.name, startTime: event.scheduledStartAt, endTime: event.scheduledEndAt, server: event.guild.id, // Add more fields as needed }; if (currentTime >= eventTime) { // If the event is over, delete it from the database const result = await eventsCollection.deleteOne({ id: event.id }); console.log('Event deleted:', result.deletedCount); } else { // If the event is not over, insert or update it in the database const existingEvent = await eventsCollection.findOne({ id: event.id }); if (!existingEvent) { const result = await eventsCollection.insertOne(eventData); console.log('Event inserted:', result.insertedId); } else { const result = await eventsCollection.replaceOne({ id: event.id }, eventData); console.log('Event updated:', result.modifiedCount); } } } catch (error) { console.error('Error processing event:', error); } } module.exports = { scanForEvents, processEvent, getGuildEvents };
d.js docs
d.js docs10mo ago
:property: Guild#scheduledEvents A manager of the scheduled events of this guild
GodOfSandwiches
GodOfSandwichesOP10mo ago
Sorry im a bit dumb can you show me what you mean
Amgelo
Amgelo10mo ago
you don't call those functions in the class, you need an instance you need to get the guild instance and then use that property to get the GuildScheduledEventManager
d.js docs
d.js docs10mo ago
:property: Client#guilds All of the guilds the client is currently handling, mapped by their ids - as long as sharding isn't being used, this will be every guild the bot is a member of
Amgelo
Amgelo10mo ago
you can use that collection to get the guilds the bot is currently on oh it looks like you have your guild already, then just use the property directly there's no GuildScheduledEvent.fetchEvents function either way, if you're using chatgpt just don't
Want results from more Discord servers?
Add your server