Hello, this is a question that I do not know very well how to write. What I want to do is that when a user registers on my website, a script is executed that makes a discord bot send a message.
Here is the code:
// When the user signup
const Discord = require('discord.js');
const client = new Discord.Client();
// send message
client.login('token');
So what is the question exactly? Does the code you’ve shared work or not?
Looking at the code sample, it’s Javascript code. Please note that we don’t support running Javascript on our servers (we only support PHP), but you can of course run Javascript in the browser of your visitors.
If this code is intended to be run in the browser, then all is good.
If this code is intended to be run on the server, it won’t because we don’t support Node.js. And before you try porting the code to PHP, note that we have blocked access to the Discord API on our servers due to rampant abuse.
I want to make that the bot only runs if the user has the page open. The code will execute on the browser. I just wanted to make sure it could be done.
I think it can be done? I’m not sure, I’m not an expert on Discord bots and the Discord API. I can tell you that there isn’t anything on the hosting side that prevents you from doing this.
Discord.js has to run on a node.js platform. If the place your hosting your bot allows you to make requests to their site, which in turn would trigger some code to run the bot, it cannot be done from this platform,
Webhooks in 99% of cases is the best option to use. This can be done from any platform as all you are doing is making a POST request to a Webhook URL. Depending on how you process the registration, either PHP or JS can be used to send Webhooks.
Hope this helps, DM me if you need more explanation.