首页 > 解决方案 > 如何添加多个条件

问题描述

如何在 discord.js 的 if 语句中添加 @ 条件,这是我的代码:

if (message.content === "/roll1"  &&  player1 = "1") {
     message.channel.send("no game is running")
}

标签: discord.js

解决方案


你的意思是提及?在这种情况下,我们可以简单地检查消息中是否没有用户提及,方法是定义提及的用户并使用 if 语句来确定是否确实找到了他的用户对象。我们可以通过键入:

const user = message.mentions.users.first() // gets the first mentioned user inside of a message
if (!user) return message.reply('Please mention a user!') // Will return the command if no user was mentioned or the user object could not be found.

推荐阅读