Get a guild object inside an express API route
I am trying to make my bot do some changes to our server based on a request to our API endpoint.
in the index.js I am starting the server and the bot, then exporting the bot to access the client on the API route.
index.js
In the route I want the bot to make changes in:
create.js
This gives me a type error
TypeError: Cannot read properties of undefined (reading 'create')
The guild I fetch is an object that only has a few properties and I can't access properties like roles, channels...etc
How can I change the fetched guild into an object to access roles and other properties and methods?4 Replies
- What's your exact discord.js
npm list discord.js
and node node -v
version?
- Not a discord.js issue? Check out #other-js-ts.
- Consider reading #how-to-get-help to improve your question!
- Explain what exactly your issue is.
- Post the full error stack trace, not just the top part!
- Show your code!
- Issue solved? Press the button!This is a pretty bad pattern. Exporting client from your index creates circular references and causes issues
Oh thank you for this note 🙌
How can I reach the result I want in a better way? What I am trying to accomplish is that we have an application where I want people to click a button and be able to make the bot create channels, roles...etc.
How can I reach the result I want in a better way? What I am trying to accomplish is that we have an application where I want people to click a button and be able to make the bot create channels, roles...etc.
you could just make raw API calls