discord bot in same server as NEXTJS Backend

How to make (export) discord bot to be alive (import) to rest of the NEXTJS server files?
19 Replies
d.js toolkit
d.js toolkit12mo ago
• What's your exact discord.js npm list discord.js and node node -v version? • Post the full error stack trace, not just the top part! • Show your code! • Explain what exactly your issue is. • Not a discord.js issue? Check out #useful-servers.
Siris
Siris12mo ago
the nextjs backend is serverless it won't be feasible with the normal discord.js library
RajGM
RajGM12mo ago
Should I host the discord bot in some nodejs server and then call it from nextjs server?
Siris
Siris12mo ago
What are you trying to do?
RajGM
RajGM12mo ago
A backend that stores some data to firebase from client then send those data to discord server
Siris
Siris12mo ago
so you just need access to the firebase backend on your website, right?
RajGM
RajGM12mo ago
yes
enffinity
enffinity12mo ago
@rajgm you could always just make an http bot to send the data to a discord server much less resource hungry for a bot that doesn't need all the features of d.js
Siris
Siris12mo ago
Yes, you could but its a bit more complex to setup
enffinity
enffinity12mo ago
if all you use it is to send a message or you could even opt for webhooks i think webhooks would be the best option
Siris
Siris12mo ago
but also if you want to use djs you can host the bot on a nodejs server and access firebase only on the website
RajGM
RajGM12mo ago
that means I need to create another server with some keys and discordbot on the same server expose it to the first server is nodejs server fesible for the discord bot for websocket connection all the time?
enffinity
enffinity12mo ago
@rajgm you could probably just use a webhook if all you want is to send data from a nextjs server to a discord channel
Siris
Siris12mo ago
yeah, also you can use a webhook bot, which only recieves interaction events on nextjs
RajGM
RajGM12mo ago
is it possible to tag someone in discord server with webhooks? I think with webhook I can't check if a member exists in discord server.
enffinity
enffinity12mo ago
yes <@id> thats how you tag someone with a bot at least thats how i do it
RajGM
RajGM12mo ago
yes concerned with this
enffinity
enffinity12mo ago
ye
RajGM
RajGM12mo ago
Thanks a lot, enf and siris. got it. use webhook to send message to server but use rest with discord bot to check member got it. only trouble in using bot in NEXTJS backend will be that the bot will be connecting and disconnecting to the server with each request. am i correct? but with rest we had to wait for client.on('ready', ... ) to perform any actions? yes, i was confusing discordJS with the native rest endpoints I can use the sub-package @discordjs/rest to send and get guild members without worrying about connection issues 👌