[英]Discord.js: Bot should mention user who did the command
I am making a bot for Discord as a first JS Project who will print out GIFs or Images after the user wrote a.GIF or.JPG command.我正在为 Discord 制作一个机器人,作为第一个 JS 项目,它会在用户编写 .GIF 或 .JPG 命令后打印出 GIF 或图像。 Additionally it will add a message.此外,它将添加一条消息。 How can i mention the user who made the command in the message above the GIF / Image ?我如何在 GIF / 图片上方的消息中提及发出命令的用户? I tried and did search but couldn't find a solution.我尝试并进行了搜索,但找不到解决方案。
client.on("message", msg => {
const sentences = ["Here is your sh*", "Take that image and shove it!", "Lol ok..."]
const texts = sentences[Math.floor(Math.random() * sentences.length)];
if (msg.content === "!Commands") {
msg.reply("Use '!GIF' for random GIFs and '!JPG'for random JPGs");
}
if (msg.content === "!GIF") {
gifNumber = 6
var randomGif = Math.floor (Math.random() * (gifNumber - 1 + 1)) + 1;
msg.reply(texts, {files: ["./gif/" + randomGif + ".gif"]});
}
if (msg.content ==="!JPG") {
jpgNumber = 2
var randomJpg = Math.floor (Math.random() * (jpgNumber - 1 + 1)) + 1;
msg.reply(texts, {files: ["./jpg/" + randomJpg + ".jpg"]});
}
});
The stringified User object will parse into a mention.字符串化的用户 object 将解析为提及。 Send 2 messages, 1 for the mention, and the 2nd for the content发送 2 条消息,1 条用于提及,2 条用于内容
msg.channel.send(msg.author);
msg.channel.send(texts, {files: ["./jpg/" + randomJpg + ".jpg"]});
You can use msg.author.id
您可以使用msg.author.id
msg.channel.send(`<@${msg.author.id}> any text`);
Will allow you to mention to user within the same message with the way mentions are made将允许您在同一条消息中以提及的方式向用户提及
<@UserID>
mentions a user <@UserID>
提及用户
<#ChannelID>
mentions a channel <#ChannelID>
提到了一个频道
<@&RoleID>
mentions a role <@&RoleID>
提到了一个角色
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.