最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How do I get a discord bot to mention a role and a user? - Stack Overflow

programmeradmin5浏览0评论

I am trying to make a bot that, whenever someone says something, it sends a message in the channel saying that that person is there and is waiting for someone to join. However, it only prints @ne1 (the role I want it to mention) as plain text. Also, when I have it mention the user, it only writes the user ID instead of actually sending @(username).

const Discord = require('discord.js');
const keepAlive = require('./server');
const client = new Discord.Client();

client.on('message', message => {
    if (message.toString().toLowerCase().includes('ne1 here')) {
        message.channel.send('@ne1, ' + message.author + ' is online and waiting for you to join!');
    }
});

keepAlive();
client.login(process.env.TOKEN);

I am trying to make a bot that, whenever someone says something, it sends a message in the channel saying that that person is there and is waiting for someone to join. However, it only prints @ne1 (the role I want it to mention) as plain text. Also, when I have it mention the user, it only writes the user ID instead of actually sending @(username).

const Discord = require('discord.js');
const keepAlive = require('./server');
const client = new Discord.Client();

client.on('message', message => {
    if (message.toString().toLowerCase().includes('ne1 here')) {
        message.channel.send('@ne1, ' + message.author + ' is online and waiting for you to join!');
    }
});

keepAlive();
client.login(process.env.TOKEN);

What I want is for it to mention the @ne1 role and the person who used the mand to run the bot. It only prints, "@ne1 571713056673890324 is online and waiting for you to join!"

Share Improve this question asked Jul 18, 2020 at 21:48 SimonSimon 771 gold badge2 silver badges12 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 8

Discord mentions (role, user, etc.) have a special format as detailed in the documentation here.

So, to mention a user you need to use their user ID <@USER_ID>/<@!USER_ID> and for a role it is similarly <@&ROLE_ID>.

In order to mention a user, you must have their User ID and use the following format: <@USERID> or <@!USERID>. For roles do <@&ROLEID> instead.

Make changes to your message to acmodate it:

message.channel.send(`<@&${ROLEID}> <@${message.author}> is online and waiting for you to join!`);

I guess you are using discord.js v12

If you want the easiest way to mention user you can use

message.channel.send(`@ne1, ${message.author} is online and waiting for you to join!`);

Also I'd use ID of role instead of just @role You can get the ID by using @role and then just using the thing discord outputs Usually something like <@&randomnumbers>

发布评论

评论列表(0)

  1. 暂无评论