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("..");
Related
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
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.
So i need help with the assign roles part - so if someone click on the reaction(emojiID) it should give the user who clicked on it the role(roleID)..
My code below sends the embed in the channel with my title & description and the emoji, but nothing happend if someone clicked on the emoji!
I use SlashCommandBuilder :
const { SlashCommandBuilder } = require('#discordjs/builders');
const fs = require('fs');
const { Client, Intents, MessageEmbed, MessageReaction } = require('discord.js');
const client = new Client({ intents: [
Intents.FLAGS.GUILDS,
Intents.FLAGS.GUILD_MEMBERS,
Intents.FLAGS.GUILD_MESSAGES,
Intents.FLAGS.GUILD_MESSAGE_REACTIONS,
Intents.FLAGS.DIRECT_MESSAGE_REACTIONS,
],
partials: ["MESSAGE", "CHANNEL", "REACTION"]
});
module.exports = {
data: new SlashCommandBuilder()
.setName('reaction')
.setDescription('Create reaction messages')
.addChannelOption((option) => {
return option
.setName('channel')
.setDescription('Choose a channel')
.setRequired(true)
})
...
async execute(interaction, client) {
const channelID = interaction.options.getChannel('channel');
const titleID = interaction.options.getString('title');
const descID = interaction.options.getString('desc');
const emojiID = interaction.options.getString('emoji');
const roleID = interaction.options.getRole('role');
let embed = new MessageEmbed()
.setTitle(titleID)
.setDescription(descID)
channelID.send({ embeds: [embed] }).then((sentMessage) => {
sentMessage.react(emojiID);
The code above is the working part - for the roles - I tried something like
async (reaction, user) => {
if(reaction.interaction.partial) await reaction.interaction.fetch();
if(reaction.partial) await reaction.fetch();
if(user.bot) return;
if(!reaction.interaction.guild) return;
if(reaction.interaction.channel.id === channelID) {
if(reaction.emoji.id === emojiID) {
reaction.interaction.guild.members.cache.get(user.id).roles.add(roleID)
}
}
};
but this is not working, please help :)
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)
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);