【发布时间】:2021-03-23 12:11:56
【问题描述】:
我对 node js 很陌生,我无法让我的 discord 机器人向我标记的用户发送消息。以下是代码应该如何的示例:
用户:howcool @MyFriend 机器人:@我的朋友是 75% 的酷!
下面是我不成功的代码:
client.on('message', async message => {
if (message.author.bot) return;
let mention = message.mentions.users.first()
if (msg.startsWith(".pfx howcool") && mention) {
message.channel.send(`${mention} is ${Math.floor(Math.random() * 100) + 1}% cool!`)
} else if (message.content === ".pfx howcool"){
message.channel.send(`You are ${Math.floor(Math.random() * 100) + 1}% cool!`)
}});
【问题讨论】:
-
当您没有提及用户时,您可能会收到错误 -
Cannot read property first of undefined如果不是这样,请告知错误
标签: javascript node.js discord discord.js bots