简体   繁体   English

你如何在 discord.js 中创建一个重启你的机器人的命令?

[英]How do you make a command which restarts your bot in discord.js?

I'm making a bot in discord.js.我正在 discord.js 中创建一个机器人。 How do I make a command that restarts the bot?如何发出重新启动机器人的命令?

You can reset a bot by using the client.destroy() method, then calling .login after again.您可以使用client.destroy()方法重置机器人,然后再次调用.login Try something like this:尝试这样的事情:

// set message listener 
client.on('message', message => {
    switch(message.content.toUpperCase()) {
        case '?RESET':
            resetBot(message.channel);
            break;

        // ... other commands
    }
});

// Turn bot off (destroy), then turn it back on
function resetBot(channel) {
    // send channel a message that you're resetting bot [optional]
    channel.send('Resetting...')
    .then(msg => client.destroy())
    .then(() => client.login(<your bot token here>));
}

If you set a ready listener in your bot, you will see that the ready event fires twice.如果您在机器人中设置了就绪侦听器,您将看到ready事件触发了两次。 I set up a ready listener like this:我像这样设置了一个现成的监听器:

client.on('ready', () => {
    console.log('I am ready!');
});

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 您如何对 discord 机器人进行编程以检测 discord.js 中的一个单词并且仅检测该单词? - How do you program your discord bot to detect a word and only that word in discord.js? 你如何让 discord 机器人重新发送你刚刚发送的图像 discord.js - How do you make a discord bot resend a image you just send discord.js 如何为 discord.js 中的机器人所在的每个 discord 服务器制作不同的阵列? - How do you make a different array for each discord server a bot is on in discord.js? 如何通过命令关闭 discord 机器人? (使用 Javascript、Node.js 和 Discord.js) - How can you make a command shut down a discord bot? (Using Javascript, Node.js and Discord.js) discord.js 问题。 我如何让机器人对一个命令给出不同的响应? - discord.js question. how do i make the bot give a different response to one command? 如何在命令文件夹中创建文件夹并使其在 discord.js v12 中工作 - How do you make folders inside a command folder and make it work in discord.js v12 Discord.js机器人程序需要帮助-如何使我的机器人每6小时自动执行一项任务而不发送命令? - Discord.js bot help needed - how can I make my bot auto do a task every 6 hours without sending it a command? Discord.js 让你的机器人等待回复 - Discord.js Make your bot wait for reply 你如何修复 Discord.JS 中的循环命令 - How do you fix the loop command in Discord.JS Discord.js 机器人命令 - Discord.js bot command
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM