问题
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"
}
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?
回答1:
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;
}
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
来源:https://stackoverflow.com/questions/50698019/bot-mention-as-a-prefix-in-discord-js