Discord Bot using Moralis?

I’m currently building a Discord Bot (node.js) and have it currently using Moralis SDK to log in to Metamask. I want it to be able to get balances and whatnot but can’t figure out how to get the server to send info back to the bot.

Currently, I’m using the Auth-Balances-NFTs (https://github.com/ChrisMoralis/Moralis-Tutorials/blob/main/01%20Auth-Balances-NFTs/01%20Auth-Balances-NFTs.html) code for a simple login page. Works fine and sends the info to the server.

How can I relay the User info back to the bot from the server? For example, user uses ‘login’ command, and the login page pops up with Moralis Authenticate on MetaMask. Click sign and server info updates but the bot doesn’t receive the info.

1 Like

Hey you are gonna need your own front page which holds the authentication logic. And a server side running that communicates with discord, for this example lets assume node.

  • When redeirecting the user to this page make sure to send there discordid, username etc as a param may it be a get or post param.

  • Next on successful authenticate, you want to let node know that there is a successful authenticate. To do this

Moralis.authenticate().then((res)=>{
// Get the User
const User = Moralis.Object.extend("User");
const query = new Moralis.Query(User);
const currUser = query.get(Moralis.user.id).first();
// Error check to prevent crash
if (currUser){
// Set the discord id for the user
curUser.set("discordId", discordIdThatYouSent);
curUser.save().then(()=>{
// Hit your node endpoint up with the user Info.
// From there because you have discord id you can send the user a message and whatever else you want to do
})
}
})
.catch((err)=>{
// Something went wrong :(
})

That’s a general jist of how I see it building out. I hope this helps

1 Like

Thanks. How do I send the user info back to the node endpoint? The main issue I have is not knowing how to relay the info from the database/server back to discord.

I’m missing something and I can’t figure it out.

You create a end point for example let’s say you are using express you could have something like.

app.post(“/registrationSucess”, (req,res)=>{
   // relayed info is under req object  

})

After u have this done. On success of registration you hit this endpoint with user data and that way node will know this is a new registration.

Hope this helps

I wasn’t using expressjs but I keep coming back to it so I might as well. Thanks