Bot crashing when calling custom /suggest command
So I have a /suggest command for my discord bot that should take the user's input, and output it to a private text channel 'bot-suggestions'. I've confirmed that it's writing the suggestion to suggestions.txt, but I think the bot is crashing when it tries to send the embed? Not entirely sure what's happening here:
Console output ('Ready! Logged in' is the bot's initialization message):
0|bot | Ready! Logged in as "OPE Bot#0931"
0|bot | Suggestion written to suggestions.txt: goddamn dude
0|bot | Embed built.
0|bot | Writing to channel: bot-suggestions
0|bot | Ready! Logged in as "OPE Bot#0931"
Discord in/output:
/suggest goddamn dude
'The application did not respond'
28 Replies
• 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.[email protected]
node -v: v18.16.0
use codeblock or code playgrounds for sharing long codes so we can read properly
? sorry I haven't posted before in here, can you elaborate?
use codeblock i.e.
```lang
code
```
Ah, apologies
lang = js, for this case
js
in place of lang
, not lang = js
💀
also, can you show the full error stackgot it lmao
The 0 | bot output is the only log I have
you should improve your error handling then, we don't know what the actual error is
how so? how would you catch the await botSuggestionsChannel.send([ embeds: [embed] }); ?
i.e. line 43
seeing the logs I think the bot is logging in after the command is ran?
the current structure is:
log "embed built"
log "writing to channel..."
channel.send embed
there's another log underneath the channel.send, but the bot looks like it's restarting before reaching it
try removving your custom error logging system, and see what's the actual error
I ran it on my local machine instead of my EC2 and it looks like it ran the command with no issue? The whole bot's stored in git and all leaves are updated
So it runs on local but not on EC2? Does it also log the same 'Ready!' Messages?
no, it outputs as expected:
It’s becoming ready an awful lot, are you running any commands that cause the client to crash and restart?
I’m just trying to figure out the circumstances of it becoming ready 4 times in a row.
I don't have any that explicitly crash it, I am however running it on a pm2, so in the event that the bot does crash, it auto-restarts.
Is there a separate error log? Try to console.log instead of console.error and see if the logs are different. That’s the only thing I can think of.
Looks like pm2 has it's own logging system:
Ahh yeah there’s your error(or one of them). Sent a user object as a field value.
Yeah I tried sending in the user.username, which should be a string, but haven't seen a difference:
Looks like even removing the fields produces the same error
And you’re sure you’re saving and restarting the client?
Seems unlikely to receive the same error on the same line if the code doesn’t match.
Suggest.js line 37 (as long as this is still being newly produced in the logs)
Try clearing the error log and see if it’s still logging errors.
Weird.
git pull
node index.js
works, but running my wrapper is when I have issues (there's a git pull with the main repo above the top line):
No dice on killing the pm2 either
Try replacing
interaction.user.username
with a static string like "hello world" and seeing if that worksThat produces the same issue oddly enough. I also tried replacing the 'suggestion' variable with a static string and it resulted in the same issue
Keep replacing variables with static values until you've isolated which expression is causing the error
You could also try using breakpoints and a debugger
Also results in the timeout issue. Could it be the way that I'm setting the channel to send to?
Oh I meant the timeout where it doesn't respond to the user in discord, not an actual timeout error
^
Current code:
Current error logs with 'pm2 logs bot --err':