【发布时间】:2021-04-16 06:40:40
【问题描述】:
我正在尝试在 repl.it 上制作一个不和谐的机器人,但我无法打开它,这就是它所说的:
Promise { <pending> }
Hint: hit control+c anytime to enter REPL.
(node:125) UnhandledPromiseRejectionWarning: Error [TOKEN_INVALID]: An invalid token was provided.
at WebSocketManager.connect (/home/runner/discord-bot/node_modules/discord.js/src/client/websocket/WebSocketManager.js:133:26)
at Client.login (/home/runner/discord-bot/node_modules/discord.js/src/client/Client.js:223:21)
Promise { <pending> }
Hint: hit control+c anytime to enter REPL.
Your Bot is now Online.
/home/runner/discord-bot/index.js:16
setInterval(() => bot.user.setActivity(`${activities[i++ % activities.length]}`, {type:"STREAMING",url:"https://www.youtube.com/watch?v=DWcJFNfaw9c" }), 5000)
^
ReferenceError: bot is not defined
at Timeout._onTimeout (/home/runner/discord-bot/index.js:16:30)
at listOnTimeout (internal/timers.js:549:17)
at processTimers (internal/timers.js:492:7)
这是我的代码:
const Discord = require('discord.js');
const client = new Discord.Client();
const prefix = 'xxx ';
var http = require('http');
http.createServer(function (req, res) {
res.write("I'm alive");
res.end();
}).listen(8080);
client.on('ready', () => {
console.log('Your Bot is now Online.')
let activities = [`gang shit`, `with the gang`, `with the gang` ],i = 0;
setInterval(() => bot.user.setActivity(`${activities[i++ % activities.length]}`, {type:"STREAMING",url:"https://www.youtube.com/watch?v=DWcJFNfaw9c" }), 5000)
});
client.on('message', message =>{
if (!message.content.startsWith(prefix) || message.author.bot) return;
const args = message.content.slice(prefix.length).split(/ +/);
const command = args.shift().toLowerCase();
if (command === 'ping'){
message.channel.send('pong!')
}
});
client.login('my-token');
别担心,我重新生成了令牌。 请帮助我,这是我的第一个机器人,如果您有什么建议请说出来,我不知道我这样做是否正确。
【问题讨论】:
标签: node.js discord discord.js