如何使用命令在 JS 中安全地注销我的 Discord Bot
How do I logout my Discordbot in JS savely with a command
我构建了一个基本的 Discord 机器人,当我在 Discord 服务器上键入相应的命令“!logout”时,我想离线。我搜索了答案,但是那些使用 discord.js 的人没有得到回应...
如果我使用 client.logout()
它会抛出错误并因
而崩溃
TypeError: client.logout is not a function
它甚至不会调用我的错误函数。
也许答案很简单,但我到处都找不到。
这是我的基本代码:
require('dotenv').config()
const Discord = require('discord.js')
const client = new Discord.Client({
intents: ["GUILDS", "GUILD_MESSAGES"],
})
client.on('ready', () => {
console.log('Bot is ready');
});
client.on("messageCreate", msg => {
if (msg.content === '!logout'){
client.logout(() => {
msg.reply('couldn^t go offline')
})
}
})
client.login(process.env.BOT_TOKEN)
谢谢! :)
process.exit(0)
来自文档:
process.exit([exitcode])
Ends the process with the specified code. If
omitted, exit uses the 'success' code 0.
To exit with a 'failure' code:
process.exit(1); The shell that executed node should see the exit code
as 1.
尝试使用函数 <Client>#destroy()
如果你想退出Node.js,你可以使用process.exit(0)
我构建了一个基本的 Discord 机器人,当我在 Discord 服务器上键入相应的命令“!logout”时,我想离线。我搜索了答案,但是那些使用 discord.js 的人没有得到回应...
如果我使用 client.logout()
它会抛出错误并因
TypeError: client.logout is not a function
它甚至不会调用我的错误函数。 也许答案很简单,但我到处都找不到。
这是我的基本代码:
require('dotenv').config()
const Discord = require('discord.js')
const client = new Discord.Client({
intents: ["GUILDS", "GUILD_MESSAGES"],
})
client.on('ready', () => {
console.log('Bot is ready');
});
client.on("messageCreate", msg => {
if (msg.content === '!logout'){
client.logout(() => {
msg.reply('couldn^t go offline')
})
}
})
client.login(process.env.BOT_TOKEN)
谢谢! :)
process.exit(0)
来自文档:
process.exit([exitcode])
Ends the process with the specified code. If omitted, exit uses the 'success' code 0.To exit with a 'failure' code:
process.exit(1); The shell that executed node should see the exit code as 1.
尝试使用函数 <Client>#destroy()
如果你想退出Node.js,你可以使用process.exit(0)