本文介绍了Bot提及是Discord.js中的前缀的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

仅当我没有在整个命令中添加空格时,我的前缀才起作用,例如:

My prefix only works if I do not add spaces to the entire command, example:

{
    "token": "",
    "prefix": "<@453463055741747200>"
}


const Discord = require("discord.js");

module.exports.run = async (bot, message, args) => {
    let something = args.join(" ");
    message.delete().catch();
    message.channel.send(something);
}

module.exports.help = {
    name: "say"
}

假设我的机器人名称是 MyBot ,上面的代码仅适用于 @MyBot 这样说,当命令是时,如何使它起作用@MyBot 这样说吗?

Let's say my bot name is MyBot, the above code would only work with @MyBot say this, how can I make it work when the command is @MyBot say this?

推荐答案

也许这行不通,因为我不使用命令处理程序,所以我使用了不同的代码样式,但是您可以尝试使用我允许的代码我的机器人要与多个全局前缀一起使用:

Maybe this won't work, because I don't use a command handler so I have a different code style, but you can try what I use to allow my bot to be used with multiple global prefixes:

var prefixes = require('./prefixes.json')
//in your case can only be var prefixes = ["<@453463055741747200>", "<@!453463055741747200>"]

let prefix = false;
for (const thisPrefix of prefixes) {
    if (message.content.toLowerCase().startsWith(thisPrefix)) prefix = thisPrefix;
}

因此消息只需要以所需的前缀开头.另外,我添加了两个提及前缀,因为不和谐是愚蠢的,并且有两种类型的用户提及:昵称提及和普通提及.因此,在您的代码中,如果机器人有缺口,它将无法正常工作.这就是为什么我还要添加< @!453463055741747200> 的原因.希望这对您有帮助

So the message just needs to start with the desired prefix. Also, I added two mention prefixes because discord is dumb and has two types of user mentions: nickname mentions and normal mentions. So in your code the bot will not work if it has a nick. That's why I added <@!453463055741747200> as well. Hope this helps you

这篇关于Bot提及是Discord.js中的前缀的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-07 00:23