Discord Bot is online But Does not reply - discord

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.

Related

Discord bot is getting the message content as null

message.content isn't working with any of the commands I made. It doesn't see my message's content. It's only working when I use message.content === ""
My code:
const Discord = require('discord.js');
const { Client, Intents, Collection } = require('discord.js')
const client = new Client({
intents: [
Intents.FLAGS.GUILDS,
Intents.FLAGS.GUILD_MESSAGES
]
});
client.on('ready', () => {
console.log(`Logged in as ${client.user.tag}!`);
});
client.on("messageCreate", (message) => {
if(message.content === ""){
message.reply("I am working");
}
});
client.login("..");

Discord.js v13 bot cannot send message

Here is my code
I tried to run it and when i run the command nothing shows up
can someone pls help me with this
const Discord = require("discord.js");
const bot = new Discord.Client({ intents: ["GUILDS", "GUILD_MESSAGES"] });
const token =
"MTAxNzgyMjQ1MjU1MTc5NDgxOA.GjO8F-.VWCMsDKV5_YdP1w6gnEME6Jucd7BN9OADesM4s";
const prefix = "lb!";
bot.on("ready", () => {
console.log("Your bot is now online");
});
bot.on("messagecreate", (message) => {
if (message.author.bot) return;
const args = message.content.slice(prefix.length).trim().split(/ +/g);
const command = args.shift().toLocaleLowerCase();
if (command === "hello") {
message.reply("Hi ${message.author}");
}
});
bot.login(token);
Message content is now a privileged intent. You may have to enable it for your bot in the Discord Developer Portal. You could (or should) also use interaction commands instead, so that you don't need that intent, as its purpose is to provide user privacy.
Hello Syed Faizan Ali Kazmi, Done Fix Your Code
// © Ahmed1Dev
const Discord = require("discord.js");
const bot = new Discord.Client({ intents: ["GUILDS", "GUILD_MESSAGES"] });
const token =
"MTAxNzgyMjQ1MjU1MTc5NDgxOA.GjO8F-.VWCMsDKV5_YdP1w6gnEME6Jucd7BN9OADesM4s";
const prefix = "lb!";
bot.on("ready", () => {
console.log("Your bot is now online");
});
bot.on("messagecreate", (message) => {
if (message.author.bot) return;
const args = message.content.slice(prefix.length).trim().split(/ +/g);
const command = args.shift().toLocaleLowerCase();
if (command === prefix + "hello") {
message.reply("Hi ${message.author}");
}
});
bot.login(token);
// © Ahmed1Dev
With Regards,
Ahmed1Dev
I rewrite the code. Hope this will work
const Discord = require("discord.js");
const bot = new Discord.Client({ intents: ["GUILDS", "GUILD_MESSAGES"] });
const token = "never post your bot token online";
const prefix = "lb!";
bot.on("ready", () => {
console.log("Your bot is now online");
});
bot.on("messageCreate", (message) => {
if (message.author.bot) return;
const args = message.content.slice(prefix.length).trim().split(/ +/g);
const command = args.shift().toLowerCase();
if (command === "hello") {
message.reply(`Hi ${message.author}`);
}
});
bot.login(token);
Also, if you didn't tick Message Content Intent, then go tick it in Discord Developer Portal

Welcome message in a specific channel when a user joins the server. (guildMemberAdd, discord.js)

How do I make it so that my bot sends a message in a specific channel when a user joins?
When I do this, it logs nothing: (Also here are my bot settings)
const Discord = require("discord.js");
const client = new Discord.Client({ intents: ["GUILDS", "GUILD_MESSAGES"] });
const { MessageEmbed } = require('discord.js');
client.on("ready", () => {
console.log("Cloud Shield has been activated.")
});
client.on("guildMemberAdd", async (member) => {
console.log(member);
});
client.login(process.env.token)
This is because you are not requesting the GUILD_MEMBERS intent.
const Discord = require("discord.js");
const client = new Discord.Client({ intents: ["GUILDS", "GUILD_MESSAGES", "GUILD_MEMBERS"] });
const { MessageEmbed } = require('discord.js');
client.on("ready", () => {
console.log("Cloud Shield has been activated.")
});
client.on("guildMemberAdd", async (member) => {
console.log(member);
});
client.login(process.env.token)

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
]
});

{update}Discord bot send only msgs but didnt send pictures

My discord bot is stucking on a loop of deleting and sending messages,
My code:
const Discord = require('discord.js');
const client = new Discord.Client();
client.on('message', msg => {
if (msg.channel.id === 'channel id') {
msg.delete();
msg.channel.send(msg.content);
}
});
client.login('token');
You need to ignore the messages sent by bots.
client.on("message", message => {
if (message.author.bot) return false
// your code goes here
});
const Discord = require("discord.js");
const client = new Discord.Client();
client.on("message", message => {
if (message.author.bot) return false;
const Attachments = [];
if (message.attachments) {
message.attachments.forEach(attachment => Attachments.push(new discord.MessageAttachment(attachment.url)));
};
message.channel.send(message.content || "", Attachments).then(message.delete());
});
client.login(process.env.DISCORD_AUTH_TOKEN);

Resources