【发布时间】:2020-02-16 04:17:01
【问题描述】:
我对编程很陌生,我想我会搞砸并尝试使用 discord.js 编写一个不和谐机器人来搞乱我的朋友。 不幸的是,虽然我遇到了一些错误,但完整的日志附在下面(UnhandledPromiseRejectionWarning: ReferenceError: command is not defined)
这里是完整的代码:
const BotName = "name"; // Name
const Token = "token"; // Token
const SpamMessage = "hello"; // Message
const YourDiscordID = 398561449078685717; // My discord ID
// Actual bot code
const Discord = require("discord.js");
const prefix = "-";
const bot = new Discord.Client({disableEveryone: true});
bot.on("ready", async () => {
bot.user.setActivity("Getting Things Ready", "https://twitch.tv/")
console.log(`${BotName} Loaded!`);
try {
let link = await bot.generateInvite(["ADMINISTRATOR"]);
console.log(link);
} catch(e) {
console.log(e);
};
});
bot.on("message", async message => {
if(message.author.bot) return;
if(!command.startsWith(prefix)) return;
if(command === `${prefix}spam`) {
if(!message.author.id === YourDiscordID) return;
let Ping = message.mentions.users.first();
setInterval(function(){
Ping.send(SpamMessage)
},
1200
);
};
});
bot.login(Token);
我希望收到“Ready!”在让机器人加入我的服务器后在控制台中,而不是它卡在带有登录 URL 的消息上,如果我在不和谐上键入命令 (-spam),我会收到下面列出的错误。
【问题讨论】:
标签: javascript node.js discord.js