I'm working on a Discord bot that should notify others when someone's ready to play. The bot is supposed to ping a role and mention the user who triggered it. But I'm running into a couple of issues:
1. The role mention shows up as plain text instead of a ping.
2. The user mention displays the ID number rather than the username.
Here's what I've got so far:
```javascript
const Discord = require('discord.js');
const botHelper = require('./helper');
const bot = new Discord.Client();
bot.on('messageReceived', msg => {
if (msg.content.toLowerCase().includes('ready to play')) {
msg.channel.send('Hey @gamers, ' + msg.author + ' wants to play!');
}
});
botHelper.keepRunning();
bot.login(process.env.SECRET_TOKEN);
The output I’m getting is: “Hey @gamers 123456789012345678 wants to play!”
How can I fix this so it properly pings the role and mentions the user? Any help would be awesome!
yo, i had similar issues b4. try using <@&ROLE_ID> for role ping and <@USER_ID> for user mention. replace ROLE_ID and USER_ID with actual IDs. also, make sure ur bot has necessary perms to ping roles. hope this helps!
I ran into a similar issue when working on my own project. The fix was to use Discord’s mention syntax for roles and users. For roles, you should use <@&ROLE_ID>, and for users, <@USER_ID>. In my case, I programmatically accessed the role via msg.guild.roles.cache and inserted the ID in the message. For example:
bot.on('messageReceived', msg => {
if (msg.content.toLowerCase().includes('ready to play')) {
const roleId = msg.guild.roles.cache.find(role => role.name === 'gamers').id;
msg.channel.send(`Hey <@&${roleId}>, <@${msg.author.id}> wants to play!`);
}
});
This approach should ensure both role and user are properly mentioned. Make sure your bot has the appropriate permissions to ping roles.
I’ve dealt with similar tagging issues in my Discord bots. One trick I found is to use Discord’s built-in formatting for mentions. For roles, you can use <@&roleID>, and for users, <@userID>. Here’s how I’d modify your code:
bot.on('messageReceived', msg => {
if (msg.content.toLowerCase().includes('ready to play')) {
const gamerRole = msg.guild.roles.cache.find(role => role.name === 'gamers');
msg.channel.send(`Hey <@&${gamerRole.id}>, <@${msg.author.id}> wants to play!`);
}
});
This should properly ping the role and mention the user. Just make sure your bot has permissions to mention roles. Also, double-check that the role name ‘gamers’ exists in your server. If it’s named differently, adjust accordingly.