Discord Bot

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');

We do not allow hosting bots.

2 Likes

hmm, instead why not use webhooks?
(I have no idea on how to do that and whether it will work)

1 Like

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.

4 Likes

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.

1 Like

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.

3 Likes

I don’t think if it would work. Discord API is blocked due to prevent abuse

1 Like

Hmm, I have a solution tho.

Use ifttt to proxy the webhooks(I use for netlify build notification)

Over PHP yes, but not JS.

1 Like

https://keegan.page/posts/netlify-to-discord-webhooks/

You can use this guide tho(it works even if discord Api is blocked

1 Like

It’s blocked also. As far as I know (have seen on older topicsl)

2 Likes

Funny that i’ve got it work before then.

1 Like

Mine didn’t work last time I tried. I’m dumb enough.

1 Like

Maybe its changed since I last tried. But I have definitely got it working on this hosting using JS.

4 Likes

Yep, ive just whipped a bit of code together using JS and it works fine.

EDIT: Also just got it to work with PHP.

3 Likes

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.