admin管理员组文章数量:1356457
I'm making a discord bot with discord.js, but my reset mand isn't working.
//!reload
if(mand === `${botsettings.prefix}reload`) {
console.clear();
bot.destroy()
bot.login(botsettings.token);
message.channel.send("Reloaded");
return;
}
It doesn't give any error; it restarts and goes back on but the mands don't update!
I tried so many different things I found, but it doesn't work.
I only have one file for all mands.
I'm making a discord bot with discord.js, but my reset mand isn't working.
//!reload
if(mand === `${botsettings.prefix}reload`) {
console.clear();
bot.destroy()
bot.login(botsettings.token);
message.channel.send("Reloaded");
return;
}
It doesn't give any error; it restarts and goes back on but the mands don't update!
I tried so many different things I found, but it doesn't work.
I only have one file for all mands.
Share Improve this question edited Jun 6, 2018 at 23:15 Andrew Myers 2,7865 gold badges35 silver badges41 bronze badges asked Jun 5, 2018 at 12:44 xVice1337xVice1337 71 gold badge1 silver badge6 bronze badges 1- why do you tag this as Java? – Stultuske Commented Jun 5, 2018 at 12:48
4 Answers
Reset to default 4If you use a nodemon system and a local batch file it will automatically reload the file for every change saved in it, and will output the new file changes.
If you need more help on this, watch a few videos from TheSourceCode on YouTube and you'll see in around 3-4 episodes on him using nodemon.
If you end up hosting it on Heroku, which is frowned upon, but I do, it will automatically reload for every change in your GitHub repository, just make sure to replace your token with process.env.token and make sure you have it set on your Heroku.
So i am guessing you have your various files set out (config etc) and one central bot.js file, and you load the bot by using something like
node bot.js
on your host machine, and obviously part of your .js file sets up the bot something like this:
const bot = new Discord.Client();
From what I can tell, your
bot.destroy()
and
bot.login(botsettings.token);
is just refreshing the const 'bot', but what it is not doing is reloading your bot.js file (with the updated mands and code).
What you would need to do, is have it set up to run a batch file or something on your host machine that terminates the entire process bot.js, and then restarts it. As this would then use the new and updated bot.js file.
The only problem is I am still figuring out how to run a batch file from my JS file, as understandably for security that feature isn't built in (other wise most websites that use JS would be vunerable to getting it to run things like format C:\)
I imagine it will involve using WSH in my JS, and I will update here if I do get it going.
I hope this was clear? let me know if you still have a question :)
In the code you provided, it seems like your only refreshing the const 'bot' instead of reloading the bot.js file.
I remend that you use a batch file.
client.destroy();
client.login();
That's not possible since there's a dead socket.
Instead, you're able to make a Shell script and have a background Daemon service the needs that you want.
本文标签: javascriptReload command discordjsStack Overflow
版权声明:本文标题:javascript - Reload command discord.js - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1743947401a2566661.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论