我如何在v12中将提及设置为Discord.js机器人的前缀 我正在使用:
client.on("message", async message => {
if (message.author.bot) return;
const args = message.content.slice(config.prefix.length).split(" ");
const command = args.shift().toLowerCase();
if (!message.content.startsWith(config.prefix)) return;
if (message.channel.type === "dm") return
if (command === "test") {
message.reply("test")
}
})
我尝试将<@ $ {client.user.id}>添加到config.json作为前缀,但没有成功。 请帮助
答案 0 :(得分:0)
如果通过将提及设置为前缀来表示要从带标签的用户启动命令,则建议您这样做。假设该命令是 @用户响应
//this looks for a command with "respond" as a second word (argument)
if(args[1] === respond){
// this defines the user you tagged as the first user tagged in the message
taggedUser = message.mentions.users.first();
//this sends a message with the tagged user
message.channel.send('you tagged ' + taggedUser)
编辑:如果您希望机器人在被标记时响应命令,请执行以下操作:
const prefix = '<@bot-id>'
并在其中放置您的机器人ID。
要帮助查找机器人前缀,请查找discord开发人员模式。 要获得有关此代码的更多帮助,请查看一段时间前发布的以下问题:here
答案 1 :(得分:0)
要设置提及机器人的前缀,您需要做的就是获取机器人的客户端ID,该ID可以使用Discord制造的this guide完成
复制完ID后,转到botconfig.json。应该看起来像这样
{
token: 'tokenhere',
prefix: '<@!ClientID>'
}
说明:为防止更改机器人的昵称,请使用“!”提及中的内容为该bot提供了一种方法,即使昵称已更改,它也可以检测到ping通