'message.author.content not working discord.js
i tried to make a ping command for DM channel so if an author says ping
in DM channel bot could reply pong
but its not working, console is not giving any error and bot is not providing any output.
client.on('messageCreate', (message) => {
if(message.author.bot) return
//command
if (message.author.content === `ping`) {
message.author.send(`pong`);
}
});
edit: message.content
doesnt work in DMs
client.on('messageCreate', (message) => {
if(message.author.bot) return
//command
if (message.content.toLowerCase() === `ping`) {
message.author.send(`pong`);
}
});
Solution 1:[1]
go to discord developers site and make sure that your message content intents are on, and DM messages will work properly
Solution 2:[2]
message.author
doesn't have any content
property. If you want to check the message content, use MessageComponent#content
as stated in the documentation.
Also make sure you enabled the correct intents and asked for verification if you bot is over 100 guilds.
Solution 3:[3]
While the other answer is something that needs to be done, it may not be the full answer to the problems you are having. Something else you will want to make sure that you have enabled in the bot code is your intents. Somewhere in your code you have a line that starts off like this: (may not be exactly this)
const client = new Client({})
Make sure you have your intents enabled there
Example 1 enable minimum intents
const client = new Client({
intents: ['GUILDS', 'GUILD_MEMBERS', 'GUILD_MESSAGES', 'DIRECT_MESSAGES'],
})
Example 2 enable all intents
const client = new Client({
intents: 131071,
})
Example 3 enable all intents with partials
const client = new Client({
intents: 131071,
partials: ['CHANNEL', 'GUILD_MEMBER', 'GUILD_SCHEDULED_EVENT', 'MESSAGE', 'REACTION', 'USER']
})
UPDATE intents: 32767 no longer includes all intents, all intents is now 131071
Solution 4:[4]
You are missing an intents
Intents.FLAGS.DIRECT_MESSAGES,
Intents.FLAGS.DIRECT_MESSAGE_REACTIONS,
Intents.FLAGS.DIRECT_MESSAGE_TYPING,
or
const client = new Discord.Client({ intents: ["GUILDS", "GUILD_MESSAGES", "GUILD_MEMBERS","DIRECT_MESSAGES","DIRECT_MESSAGE_REACTIONS","DIRECT_MESSAGE_TYPING"] });
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | coco bar |
Solution 2 | loom |
Solution 3 | |
Solution 4 |