Receiving empty content / embed from other bot by slash command in Discord.js - discord.js

I'm using Discord.js 14.6.0
When user use slash command (/) with other bot, I can receive message, but the embeds and content are empty.
(I can get embeds and content when bot send normal message)
I've already checked "Privileged Gateway Intents > MESSAGE CONTENT INTENT" in Discord Bot setting
And here's my code:
const { Client, GatewayIntentBits , Partials , EmbedBuilder } = require('discord.js');
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent,
GatewayIntentBits.GuildMembers,
],
partials: [Partials.Channel],
});
client.login(TOKEN);
client.on("ready", () => {
console.log("Server is on!")
});
client.on("messageCreate", (message) => {
console.log(message)
// When using slash commamd by other Bot, `message.content` result: []
});

Related

TypeError when trying to create a discord bot

I'm trying to build a discord bot that sends data to an airtable. This one sends user info when they join my server. I have the following code, but every time I try to run it, I get the following error:
TypeError: Cannot read properties of undefined (reading 'GUILDS')at Object.
This is the code:
const { Intents } = require('discord.js');
const Discord = require('discord.js');
const Airtable = require('airtable');
const client = new Discord.Client({
token: 'TOKEN_ID',
intents: [Intents.GUILDS, Intents.GUILD_MEMBERS]
});
Airtable.configure({ apiKey: 'API_KEY' });
const base = Airtable.base('BASE_ID');
client.on('guildMemberAdd', member => {
base('New Members').create({
'Username': member.user.username,
'Time Joined': new Date().toISOString()
}, function(err, record) {
if (err) {
console.error(err);
return;
}
console.log(`Added new record with ID ${record.getId()}`);
});
});
client.login();
Using Discord.js v14, the way to declare intents is as follows:
import { Client, GatewayIntentBits } from "discord.js";
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMembers
]
});
and your token should be put in client.login
client.login("your-bot-token");

Discord Bot is online But Does not reply

My discord bot is online but there is something wrong. The bot does not reply my code.
const { Client, GatewayIntentBits } = require('discord.js');
const Discord = require("discord.js")
const TOKEN = "MyToken"
const client = new Discord.Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
]
})
client.on("ready", () => {
console.log(`Logged in as ${client.user.tag}`)
})
client.on("messageCreate", (message) => {
if (message.content === "hi") {
message.reply("Hello World")
}
})
client.login(TOKEN)
Bot does not reply the code
Check the permissions in the invite link and intents you set of the bot.

My discord bot is not responding even though there is no error

const { Client, Intents } = require('discord.js');
const client = new Client({ intents: [Intents.FLAGS.GUILDS] });
const config = require('./config.json');
client.once('ready', () => {
console.log("go");
})
client.on('message', (message) => {
if(message.content == "ping"){
message.channel.send("pong");
}
})
client.login(config.token);
There is no error in the code, but when I type ping, the bot does not respond, does anyone know why?
It's because you don't have the GUILD_MESSAGES intent enabled !
Replace that line :
const client = new Client({ intents: [Intents.FLAGS.GUILDS] });
with
const client = new Client({ intents: [Intents.FLAGS.GUILDS,Intents.FLAGS.GUILD_MESSAGES] });
As you can see from the official documentation :
GUILD_MESSAGES intent let us have events and one of them is MESSAGE_CREATE (emits when a message is created (sent))
Since after the new update of discord.js, providing intents is an integral part of Disocrd bots.
const {Client, Intents, Collection} = require('discord.js')
const client = new Client({intents:[Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES]})

How to fix 'CLIENT_MISSING_INTENTS' error in discord.js?

const Discord = require('discord.js');
const client = new Discord.Client();
client.once('ready', () => {
console.log('Meep is online!');
});
client.login('my token was here');
When I run code, I get 'CLIENT_MISSING_INTENTS' error, how to fix it?
I was not getting this error in older discord.js versions, I started getting this error when I updated to the new discord.js version.
You can use any intents you want
with this intents you just can see guilds and messages in guilds
const Discord = require('discord.js');
const client = new Discord.Client({intents : [
Discord.Intents.FLAGS.GUILDS,
Discord.Intents.FLAGS.GUILD_MESSAGES
]})
client.once('ready', () => {
console.log('Meep is online!');
});
client.login('my token was here');
const client = new Client({
intents: [
Intents.FLAGS.GUILDS,
Intents.FLAGS.GUILD_MEMBERS,
Intents.FLAGS.GUILD_BANS,
Intents.FLAGS.GUILD_EMOJIS_AND_STICKERS,
Intents.FLAGS.GUILD_INTEGRATIONS,
Intents.FLAGS.GUILD_WEBHOOKS,
Intents.FLAGS.GUILD_INVITES,
Intents.FLAGS.GUILD_VOICE_STATES,
Intents.FLAGS.GUILD_PRESENCES,
Intents.FLAGS.GUILD_MESSAGES,
Intents.FLAGS.GUILD_MESSAGE_REACTIONS,
Intents.FLAGS.GUILD_MESSAGE_TYPING,
Intents.FLAGS.DIRECT_MESSAGES,
Intents.FLAGS.DIRECT_MESSAGE_REACTIONS,
Intents.FLAGS.DIRECT_MESSAGE_TYPING
]
});

My discord bot isn't working after 13.0.0

I am trying out discord.js version 13.1.0 and I am following discord's guide on how to setup a bot. I have followed all the steps. When I have the bot running, and I send a message or a command into the server, nothing gets printed to the console. Any ideas?
My code:
const { Client, Intents } = require("discord.js");
const client = new Client({ intents: [Intents.FLAGS.GUILDS] });
client.once("ready", () => {
console.log("Ready!");
});
client.on("interactionCreate", (interaction) => {
console.log(interaction);
});
client.login(process.env.TOKEN);
From the Discord Developer Portal:
An Interaction is the message that your application receives when a user uses an application command or a message component.
By an application command is meant a special type of command, that you have to register against the Discord API. To learn more about application commands, read this.
From the discord.js docs main page, how to register an application (slash) command:
const { REST } = require('#discordjs/rest');
const { Routes } = require('discord-api-types/v9');
const commands = [{
name: 'ping',
description: 'Replies with Pong!'
}];
const rest = new REST({ version: '9' }).setToken('token');
(async () => {
try {
console.log('Started refreshing application (/) commands.');
await rest.put(
Routes.applicationGuildCommands(CLIENT_ID, GUILD_ID),
{ body: commands },
);
console.log('Successfully reloaded application (/) commands.');
} catch (error) {
console.error(error);
}
})();
However if you are looking for a way to reply to (or just capture) a normal message sent in a TextChannel, you are probably looking for the messageCreate event.
client.on("messageCreate", (message) => {
console.log(message);
});
Also note that to receive messageCreate event, you need GUILD_MESSAGES intent.
const client = new Discord.Client({ intents: ["GUILDS", "GUILD_MESSAGES"] });

Resources