Is there a way to loop through each guild and channel without getting error using fetch?
Basically, right now I am using try/catch without logging the error(s), because it works. But, if I do not use try/catch, I get an "unknown message" error, even after it does return the correct message and print once.
DT
d.js toolkit•15d ago
- 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!
- ✅
Marked as resolved by OPS
Swyftey•15d ago
The image on the right is what happens without using try/catch
DD
d.js docs•15d ago
Documentation suggestion for @Swyftey:
:mdn: Promise.prototype.catch()
The catch() method of Promise instances schedules a function to be called when the promise is rejected. It immediately returns an equivalent Promise object, allowing you to chain calls to other promise methods. It is a shortcut for Promise.prototype.then(undefined, onRejected).
S
Swyftey•15d ago
but is it OK to use catch without logging anything, or adding anything?
G
gwapes•15d ago
Why are you trying to fetch the message when you already have it?
S
Swyftey•15d ago
I want the message to be searched for within all guilds and channels thre bot is in
so, it is most likely erroring when the message is NOT found within the loop
G
gwapes•15d ago
But you already have the message?
.targetMessage is the message
There’s so many better ways of doing what you’re doing
S
Swyftey•15d ago
nooo
I need to use nonce
I need the message ID within the nonce
Sorry, forgot to share that
G
gwapes•15d ago
So targetMessage.id, simple
S
Swyftey•15d ago
no
wait
G
gwapes•15d ago
Because what you’re doing, or trying to do, is just api spam
You’re unnecessarily spamming the api when the data is right there in front of you
S
Swyftey•15d ago
I'm not trying to get that target message though
I need to get the message from the ID that the targetmessage nonce contains
I'm using nonce as an alternative to customID
Is there any way to stop the loop once found?
or avoid the API spam
G
gwapes•15d ago
But according to the docs it’s a random number or string, so that won’t help you…
S
Swyftey•15d ago
What I did works
it's just the loop causing API spam
Not sure I have another way
G
gwapes•15d ago
But what you’re doing may work but it’s horrendous
What’s the actual end goal?
Are you trying to fetch the reference message or something?
S
Swyftey•15d ago
The bot is for cross-server messaging
lol
hang on ill send a short clip to try and explain what it's doing
S
Swyftey•15d ago
S
Swyftey•15d ago
basically
I need the original message ID, so the bot's message contains the message ID in the nonce string
yes, nonce is used for "checking message delivery", but also can be used for my purpose
still checks for message delivery
G
gwapes•15d ago
If you’re using buttons why not attach the original message id in the custom id? <customId>-<messageId> .split('-')
S
Swyftey•15d ago
mm but
when I say "original message"
i mean a message the user sends within a "call"
for example, the command I was working on is for "reports"
if I don't get the message ID of the original message (not the one the bot sent), the report doesn't know the true details
S
Swyftey•15d ago
S
Swyftey•15d ago
^ working with nonce
G
gwapes•15d ago
I guess you’ll have to wait for someone else who understands more
S
Swyftey•15d ago
lol
alright
I think everything works and there shouldn't be a problem with it other than the loop, is there a way to check for a message within all servers/channels without causing API spam?
If you don't know, no worries
M
Mark•15d ago
It's not possible, messages are unique to the channel they're in
S
Swyftey•15d ago
nonce has a limit of 25
characters
lol
I'm trying to fix the loop if I can
I see.
But
How often should you be querying to/from a database
for example
I would want that id to be stored for every created message within a "call"
Is this OK?
Ok.
I guess I just didn't know if it would be possible to throttle the database or server depending on amount of requests at a time
So, I would only loop through the guilds to find the channel, or does .get() on a channel ID return any channel ID from any server?
I probably know this one, just double checking
gotcha
thanks
Support server for discord.js, a Node.js module to interact with the Discord bot API.
58KMembers
View on DiscordWant results from more Discord servers?
More PostsBot cannot play musicI recently started a bot that play music, everything works just fine, no error, the bot is able to fThis interaction failed but components are workingI'm trying to create an interactive settings command by using interactable dropdown menus and buttoninteraction.channel is null in DMit works for servers, but not in direct message as 'user app'.
I already use as suggestions of otheDiscord cdn not working?I'm storing a link of an image attachment `...cdn.discordapp.com/attachments...` and the content is this isn’t really an error but more of a questionHow would you exactly use the presence to detect if a specific role has online members? as i am tryduplicate responsesSlash command Duplicate error!!i keep getting this error trying to refresh my slash cmds using the command deploy from discordjs.gucrash even if I have a trycatchThe bot crashes even if I put a trycatch(error).Trouble with collector and interactionsHere's the part of my code that's causing errors:
```javascript
async function handleListReactions(unknown interactionhello everyone
i have a ticket bot and when the admin want to close the ticket and press the button What are the exact differences between a Webhook and a Webhook client?I've read the page on the [discordjs.guide](https://discordjs.guide/popular-topics/webhooks.html#whaChecking if a user is mobiile```JS
client.on('messageCreate', async (message) => {
// Check if the user is online and has preSharding QuestionsHello,
As my bot is nearly reaching the 2k servers. I need to prepare it to sharding but I have soRepeating interactionIs there a way to use the 'interaction.update' multiple times? So i can make like one button after aWhat Discord.js features have the potential to hit the limit/go over the set Discord API limits?Where can I even find Discord's API limits? I just want to make sure that what I am doing with my boError when i do npm install discord.jsi don’t know how to fix this at all and i’m beyond confused i’ve tried so many times i am useing VisSimple question, how can I check if an incoming message is *specifically* a slash command?How can I check to see if an incoming message (messageCreate) is a slash command? Sometimes a typo cdiscord voice enginehello im just asking if someone got an alternative discord voice engine that work on windowsDeleting Ephemeral MessagesIs there any sort of way to reply to an interaction privately and then delete the reply?Button Automatically PressingHello! Im currently working on a bot using oauth2. Im in the middle of rewriting how i handle refres