guildBanAdd and messageDelete event not triggering, Discord.js v14 - javascript

my guildBanAdd event on discord.js v14 doesn't trigger whenever I ban a user, same as the messageDelete event. Do I need to give my bot any specific permission aside the adminstrator permission it has or is there an Intent that is missing in the client
other events such as interactionCreate and messageCreate works just fine
`
module.exports = {
name: "guildBanAdd",
async execute(guild, user, client) {
console.log('I was called: guildBanAdd');
},
};
`
`
module.exports = {
name: "messageDelete",
async execute(message, client) {
console.log(`delete logs: ${message}`);
},
};
`
my client Intents
`
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent,
GatewayIntentBits.GuildMembers,
],
});
`
I have also enabled all three Privileged Gateway Intents on the discord application dashboard as well.
Thank you.
I tried banning a user and expected something to be logged but nothing showed, I also tried deleting a user content and nothing showed

Related

How can I make bot receive DM on Discord js v14? [duplicate]

This question already has an answer here:
message.content doesn't have any value in Discord.js
(1 answer)
Closed 4 months ago.
module.exports = {
name: 'messageCreate',
execute(message) {
if (message.channel.type == 'DM') {
console.log('Dm recieved')
client.channels.get('1026279100626767924').send(message);
}
}
};
I created event handling by referring to the Discord JS guide. I want my bot to receive a DM and send that message to my admin channel.
But the bot is not recognizing the DM
What should I do
(I'm using a translator)
You can use messageCreate event for listening your bot's DMs.
client.on("messageCreate", async message => {
if (message.guild) return;
console.log(`Someone sent DM to me => ${message.content}`);
await client.channels.cache.get(CHANNEL_ID).send(messsage.content);
});
You need to include partials Channel and Messages configurations on creating client:
const client = new Client({
intents: [
GatewayIntentBits.DirectMessages,
GatewayIntentBits.MessageContent
],
partials: [
Partials.Channel,
Partials.Message
]
})
That solved it for me!
There could be a couple problems with this.
First off, it could be your Intents.
Intents allow your bot to process certain events.
The intents that you will want are:
DirectMessages
MessageContent (this one may not be required, I am unsure).
So, go to where you initialize your client. It should look something like this:
const Discord = require("discord.js");
const client = new Discord.Client();
and change it into this:
const Discord = require("discord.js");
const { GatewayIntentBits, Client } = Discord;
const client = new Client({
intents: [
GatewayIntentBits.DirectMessages
GatewayIntentBits.MessageContent
]
});
The second issue could be that your message handler isn't detecting it properly.
Like the other answer says, you should just determine if there is no Guild attached to the message.
client.on("messageCreate", async(message) => {
if(!message.guild) {
client.channels.cache.get("YOUR_ID").send(message);
}
});
There could be other issues, but those two are the most probable. Considering you're not getting any errors, I'd presume it's the first one, the issue with Intents.
Hope this helps!

DisallowedIntents if im run discord bot in terminal

const { Client, GatewayIntentBits } = require("discord.js");
const client = new Client({
intents: [
GatewayIntentBits.Guilds, //all problem here
GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent,
GatewayIntentBits.GuildMembers
],
});
client.login("TOKEN");
You get this problem because you are accessing privileged intents. To fix this go to https://discord.com/developers/applications/ click on your bot. Then go to the section that says bot and scroll down to Privileged Gateway Intents. Enable server members and message content intent. After that it should be fixed.

How to get users in voice channel without cache in DiscordJS?

I'm trying to get all users connected to a voice channel on my server. When someone talks to a bot in #general, I want to get the users inside Voice Channel 1.
I'm using Node 17 and DiscordJS 13.
This is my code:
message.guild.channels
.fetch(channelID, { cache: false, force: true })
.then((channels) => {
console.log(channels.members);
});
Also, I tried this one:
let voiceChannel = client.guilds.cache
.get(process.env.DISCORDJS_GUILD_ID)
.channels.cache.get(process.env.DISCORDJS_CHANNEL_ID);
let membersInChannel = voiceChannel.members;
console.log(membersInChannel);
But, it always returns the voice channel users that joined when I start the node app. If someone leaves the voice channel, it keeps showing him in the console.log when I say something to the bot in #general. How can I achieve this?
I've had the same problem. Although I added { force: true } as the option in fetch, it always showed the same number of members when I started the app, ignoring the ones who joined/left the channel.
Enabling the GUILD_VOICE_STATES intent solved this. So don't forget to add it to your client:
const { Client, Intents } = require('discord.js');
const client = new Client({
intents: [
Intents.FLAGS.GUILDS,
Intents.FLAGS.GUILD_MESSAGES,
Intents.FLAGS.GUILD_VOICE_STATES,
],
});

Discord Bot isn't responding

For some reason, the basic ping pong command isn't working. I copied and pasted it from a website, but I am not sure what is wrong with it.
const { Client, Intents } = require('discord.js');
const client = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES] });
client.login('hidden')
client.once('ready', () => {
console.log('Ready!');
});
client.on('interactionCreate', interaction => {
if (!interaction.isCommand()) return;
const { commandName } = interaction;
if (commandName === 'ping') {
interaction.reply('Pong.');
}
});
There is no log error which makes it weirder. I know it is connecting because the bot appears online when I do a node index.js in the cmd panel.
Firstly, I recommend that you fix the indentation at the beginning and move the client.login call to the end, as that's how the discord.js docs do it.
Additionally, are you sure you're using Discord.js v13? These events were added in v13, so if you run it with Discord.js v12, your bot will run, but your functions will never be called.
Otherwise, your code looks good (to me), but I'm not an expert.

Event messageCreate not firing/emitting when I send a DM to my bot (discord.js v13)

I made this code for logging the DMs that are sent to my bot:
client.on('messageCreate', async message => {
if (message.author.bot) return;
const attachment = message.attachments.first()
if (message.channel.type === 'DM') {
console.log(message.content)
const dmLogEmbed = new MessageEmbed()
.setColor("RANDOM")
.setTitle(`${message.author.tag} dmed the bot and said: `)
.setDescription(message.content)
.setFooter(`User's id: ${message.author.id}`)
if (message.attachments.size !== 0) {
dmLogEmbed.setImage(attachment.url)
}
client.channels.fetch("852220016249798756").then((channel) => {
channel.send({ embeds: [dmLogEmbed] })
})
}
});
But when updating to discord.js v13 it didn't work anymore, for what I understood the only change is that the 'dm' channel type isn't 'dm' anymore but 'DM', so I changed it in my code, but it is still not working and I don't really know why.
Make sure you have DIRECT_MESSAGES in your client's intents.
const client = new Discord.Client({ intents: ["GUILDS", "GUILD_MESSAGES", "DIRECT_MESSAGES"] });
There is a breaking change in the Discord API v8. For reference see here.
On Discord API v8 and later, DM Channels do not emit the CHANNEL_CREATE event, which means discord.js is unable to cache them automatically. In order for your bot to receive DMs, the CHANNEL partial must be enabled.
So we need to enable the partial CHANNEL as well. Keep in mind that when dealing with partial data, you often want to fetch the data, because it is not complete. However this doesn't seem to be your case, if you are using the messageCreate event. The message received is not partial nor message.channel. To check if something is partial, you can use the .partial property. For example Message.partial or Channel.partial.
const client = new Discord.Client({ intents: ["GUILDS", "GUILD_MESSAGES", "DIRECT_MESSAGES"], partials: ["CHANNEL"] });
Now it should work as good old discord.js v12.

Categories