【发布时间】:2020-12-12 14:28:15
【问题描述】:
现在,在你说之前已经发过这个之前,我有不同的情况。
说完这些,让我们继续这个问题。
我正在为一个朋友制作一个 Discord 机器人,该朋友为团队和类似的事情履行职责。
也请注意,我正在使用 Discord.JS 的 Sitepoint version,因为我是初学者。
我希望机器人在节目因某种原因被取消时向某个频道发送消息。例如,他们会发送如下内容:
afv!cancel Roblox went down.
或类似的东西。
但是每次发送消息,每个空格都会变成这样的逗号:
:x: The show has been cancelled because: "Roblox,went,down.". Sorry for that!
这是处理执行命令的 index.js 代码:
bot.on('message', msg => {
const args = msg.content.split(/ +/);
const command = args.shift().toLowerCase();
const prefix = command.startsWith("afv!");
if (prefix == true) {
console.info(`Called command: ${command}`);
if (!bot.commands.has(command)) return;
msg.delete(1);
try {
bot.commands.get(command).execute(msg, args, bot);
} catch (error) {
console.error(error);
msg.reply('there was an error trying to execute that command!');
};
还有cancelled.js 文件:
module.exports = {
name: 'afv!cancel',
description: "in-case the show gets cancelled",
execute(msg, args, bot) {
if (msg.member.roles.find(r => r.name === "Bot Perms")) {
const reason = args.replace(/,/g, " ");
bot.channels.get('696135370987012240').send(':x: **The show has been cancelled** because: "' + args + '". *Sorry for that!*');
bot.user.setActivity("AFV! | afv!help", { type: 'PLAYING' });
} else {
msg.reply('you are missing the role: Bot Perms!');
}
},
};
顺便说一句,在执行命令时,它会打印:
TypeError: args.replace is not a function
感谢阅读! :)
【问题讨论】:
-
似乎您需要使您的数据结构符合它想要的方式。你总是可以转换成十六进制
标签: javascript discord discord.js