Deploying via github always crashes after 4-5 minutes
I am creating a discord bot and when I commit to github and deploy it, it starts fine at first. But after 4-5 minutes, it always crashes with error "websocket: close 4004: Authentication failed.
This happens even if I rewrite only the comments without rewriting the code, so it does not seem to originate from the code.
It seems that the discord bot token set in the environment variable cannot be used via github commit.
After resetting the token and redeploying, it starts up normally and runs without problems.
Also, when I press the redeploy button on railway, the above error does not occur.
What is the difference between when I go through github and when I press the redeploy button?Why does it start up fine the first time and then after 5 minutes it fails?
The project id is as follows
8ef117af-d772-493d-90eb-b33b653eb24a
61 Replies
Project ID:
8ef117af-d772-493d-90eb-b33b653eb24a
did you set your discord bot token as a variable?
I'm setting it here
well that error is because of authentication.
maybe your token is invalid
Yes, I think so, because resetting the tokens in the discord developer portal fixes it. So I reset the token on each deploy, is this normal behavior?
uhmmm no, your token doesn't reset without a reason.
I also find it odd that the token becomes invalid 5 minutes after deployment....
the only reason I see to a token reset is when you leak it in a public repository or when you do too much logins to discord (about 1000 logins per minute i think)
you receive a message from Discord tho
The repository is private
Also, make sure you're grabbing the right token.
You need the bot token, not the OAuth2 token
I think it will be a Invalid Session (opcode 9) when there are 1000 requests
As long as I don't deploy, the bot is working fine all the time, so it's a mystery
If you don't receive a message from Discord, then its not that
I always get my bot token from here
maybe it could be your intents? try enabling those
It's okay
When I redeploy with the button here, the problem does not occur. The problem only occurs when I modify the code and commit it to github
so there's something that you're modifying that's breaking the authentication.
are you touching the
discordgo.New
in someway?By touch, do you mean whether I modified the "discordgo.new" or not?
yeah
Sorry my English is not up to par
No. The same error will occur if only the comment is modified
well i'm out of ideas.
if you can make your repository public to other people see would help.
Sorry, I'm a beginner and I'm not sure how to do this, but do you mean to put the URL of the repository I made public on this thread?
It's OK to temporarily publicize it (though it's not code that can be shown to others...)
github repository i mean, if you can would help
this?
yes
GitHub
GitHub - Rocochi/go-degu-ai-for-discord
Contribute to Rocochi/go-degu-ai-for-discord development by creating an account on GitHub.
I translated as much as I could, but I think there is some Japanese sometimes, so if you don't understand, just ask
so what's the websocket handler for
you mean the discord one?
that's their API gateway (listen for messages etc)
in their code they have a /ws handler
I am also creating a desktop app and I can see what this bot has to say in that app
ah okay so it's not like discord connects to that endpoint
yeah
well idk maybe that library you are using isn't playing nicely with discords api
well im using that library in a bot of mine since 2022 and i've never had any problems
it's not hosted in railway tho
I see... well, it works ok if I rewrite the token every time I deploy it, so it's just a pain in the ass, not that it won't work... so I might as well leave it as is
not hosted on railway? banned
lol
in my defense it was before i knew railway ok
move it to railway?
it's hosted in a free VPS loland i don't want to touch it, it's working 🙏
it's a go bot, it will be 20 cents
okay at least tell us the library version it uses
I think it used to work when I used to run it in python (I don't remember when this started happening)
just seems like a code issue then tbh
go 1.21
require (
github.com/ayush6624/go-chatgpt v0.3.0
github.com/bwmarrin/discordgo v0.27.1
github.com/gorilla/websocket v1.5.0
)
require (
golang.org/x/crypto v0.13.0 // indirect
golang.org/x/sys v0.12.0 // indirect
)
hmmbtw my deps
godotenv 🤣
main function
any alternative?
railway
what if im running on dev?
on production i dont use godotenv btw
dev environment
cc @rokochi
I'll try to get as close to this as possible
(tomorrow...)
Thanks so much