MongooseError: Model.findOne() no longer accepts a callback at Function

Mongoose dropped support for callbacks from its node.js driver as of version 5.0. You can use async/await instead: module.exports = { data: new SlashCommandBuilder().setName(‘dbtest’).setDescription(‘db test’), async execute(interaction) { try { const data = await testSchema.findOne({ GuildID: interaction.guild.id, UserID: interaction.user.id, }); if (!data) { testSchema.create({ GuildID: interaction.guild.id, UserID: interaction.user.id, }); } if (data) { console.log(data); } … Read more

Fetch more than 100 messages

What you can do is use an async/await function and a loop to make sequntial requests async function lots_of_messages_getter(channel, limit = 500) { const sum_messages = []; let last_id; while (true) { const options = { limit: 100 }; if (last_id) { options.before = last_id; } const messages = await channel.fetchMessages(options); sum_messages.push(…messages.array()); last_id = messages.last().id; … Read more

Having trouble sending a message to a channel with Discord.js [duplicate]

You need to enable the GUILD_MESSAGES intent: const client = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES] }); This will enable you to receive the MESSAGE_CREATE event for messages sent in guilds. A full list of intents can be found on the Discord developer docs. Additionally, if you are using Discord.js v13, the message event has been … Read more

How do I list all Members with a Role In Discord.Js

<Role>.members returns a collection of GuildMembers. Simply map this collection to get the property you want. Here’s an example according to your scenario: message.guild.roles.get(‘415665311828803584’).members.map(m=>m.user.tag); This will output an array of user tags from members that have the “go4” role. Now you can .join(…) this array to your desired format. Also, guild.member(message.mentions.users.first()).addRole(‘415665311828803584’); could be shortened down … Read more

Discord.js: Invalid bitfield flag or number: GUILDS

In discord.js v14, intent flags are available from GatewayIntentBits. const { Client, GatewayIntentBits } = require(‘discord.js’); const client = new Discord.Client({ intents: [ GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages, ] }) List of changes: v12/v13 v14 GUILDS GatewayIntentBits.Guilds GUILD_BANS GatewayIntentBits.GuildBans GUILD_EMOJIS_AND_STICKERS GatewayIntentBits.GuildEmojisAndStickers GUILD_INTEGRATIONS GatewayIntentBits.GuildIntegrations GUILD_INVITES GatewayIntentBits.GuildInvites GUILD_MEMBERS GatewayIntentBits.GuildMembers GUILD_MESSAGE_REACTIONS GatewayIntentBits.GuildMessageReactions GUILD_MESSAGE_TYPING GatewayIntentBits.GuildMessageTyping GUILD_MESSAGES GatewayIntentBits.GuildMessages GUILD_PRESENCES GatewayIntentBits.GuildPresences GUILD_SCHEDULED_EVENTS GatewayIntentBits.GuildScheduledEvents GUILD_VOICE_STATES … Read more

Checking if a message was sent from a DM channel type not working

Are you sure you haven’t updated your discord.js version and you’re still using v12? Channel types in v13 are now uppercase and align with Discord’s naming conventions. See below the changes: channel type v12 v13 DM channel dm DM group DM channel N/A GROUP_DM guild text channel text GUILD_TEXT guild text channel’s public thread channel … Read more

setPresence activity type in discord.js v14 can only be set to “PLAYING”

In v14, you will need to use the ActivityType enums or numbers. You can import it from discord.js: const { Client, GatewayIntentBits, ActivityType } = require(‘discord.js’); And use it like this: client.user.setPresence({ activities: [{ name: `discord.js v14`, type: ActivityType.Watching }], status: ‘dnd’, }); List of ActivityTypes: v13 v14 v14 value “COMPETING” ActivityType.Competing 5 “CUSTOM” ActivityType.Custom … Read more