R
Railway14mo ago
rokochi

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
Percy
Percy14mo ago
Project ID: 8ef117af-d772-493d-90eb-b33b653eb24a
rokochi
rokochi14mo ago
No description
No description
rokochi
rokochi14mo ago
No description
ThallesComH
ThallesComH14mo ago
did you set your discord bot token as a variable?
rokochi
rokochi14mo ago
No description
rokochi
rokochi14mo ago
I'm setting it here
ThallesComH
ThallesComH14mo ago
well that error is because of authentication. maybe your token is invalid
rokochi
rokochi14mo ago
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?
ThallesComH
ThallesComH14mo ago
uhmmm no, your token doesn't reset without a reason.
rokochi
rokochi14mo ago
I also find it odd that the token becomes invalid 5 minutes after deployment....
ThallesComH
ThallesComH14mo ago
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
rokochi
rokochi14mo ago
The repository is private
ThallesComH
ThallesComH14mo ago
Also, make sure you're grabbing the right token. You need the bot token, not the OAuth2 token
rokochi
rokochi14mo ago
No description
rokochi
rokochi14mo ago
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
ThallesComH
ThallesComH14mo ago
If you don't receive a message from Discord, then its not that
rokochi
rokochi14mo ago
I always get my bot token from here
No description
ThallesComH
ThallesComH14mo ago
maybe it could be your intents? try enabling those
rokochi
rokochi14mo ago
No description
ThallesComH
ThallesComH14mo ago
No description
rokochi
rokochi14mo ago
No description
rokochi
rokochi14mo ago
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
ThallesComH
ThallesComH14mo ago
so there's something that you're modifying that's breaking the authentication. are you touching the discordgo.New in someway?
rokochi
rokochi14mo ago
By touch, do you mean whether I modified the "discordgo.new" or not?
ThallesComH
ThallesComH14mo ago
yeah
rokochi
rokochi14mo ago
Sorry my English is not up to par No. The same error will occur if only the comment is modified
ThallesComH
ThallesComH14mo ago
well i'm out of ideas. if you can make your repository public to other people see would help.
rokochi
rokochi14mo ago
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...)
ThallesComH
ThallesComH14mo ago
github repository i mean, if you can would help
rokochi
rokochi14mo ago
No description
rokochi
rokochi14mo ago
this?
ThallesComH
ThallesComH14mo ago
yes
rokochi
rokochi14mo ago
GitHub
GitHub - Rocochi/go-degu-ai-for-discord
Contribute to Rocochi/go-degu-ai-for-discord development by creating an account on GitHub.
rokochi
rokochi14mo ago
I translated as much as I could, but I think there is some Japanese sometimes, so if you don't understand, just ask
Brody
Brody14mo ago
so what's the websocket handler for
ThallesComH
ThallesComH14mo ago
you mean the discord one? that's their API gateway (listen for messages etc)
Brody
Brody14mo ago
in their code they have a /ws handler
rokochi
rokochi14mo ago
I am also creating a desktop app and I can see what this bot has to say in that app
Brody
Brody14mo ago
ah okay so it's not like discord connects to that endpoint
rokochi
rokochi14mo ago
yeah
Brody
Brody14mo ago
well idk maybe that library you are using isn't playing nicely with discords api
ThallesComH
ThallesComH14mo ago
well im using that library in a bot of mine since 2022 and i've never had any problems
No description
ThallesComH
ThallesComH14mo ago
it's not hosted in railway tho
rokochi
rokochi14mo ago
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 Deguyada
Brody
Brody14mo ago
not hosted on railway? banned
rokochi
rokochi14mo ago
lol
ThallesComH
ThallesComH14mo ago
in my defense it was before i knew railway ok
Brody
Brody14mo ago
move it to railway?
ThallesComH
ThallesComH14mo ago
it's hosted in a free VPS lol
and i don't want to touch it, it's working 🙏
Brody
Brody14mo ago
it's a go bot, it will be 20 cents okay at least tell us the library version it uses
rokochi
rokochi14mo ago
I think it used to work when I used to run it in python (I don't remember when this started happening)
Brody
Brody14mo ago
just seems like a code issue then tbh
rokochi
rokochi14mo ago
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 ) hmm
ThallesComH
ThallesComH14mo ago
btw my deps
module foxybot

go 1.18

require (
github.com/bwmarrin/discordgo v0.25.0
github.com/joho/godotenv v1.3.0
github.com/robfig/cron/v3 v3.0.0
)

require (
github.com/gorilla/websocket v1.4.2 // indirect
golang.org/x/crypto v0.0.0-20210421170649-83a5a9bb288b // indirect
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68 // indirect
)
module foxybot

go 1.18

require (
github.com/bwmarrin/discordgo v0.25.0
github.com/joho/godotenv v1.3.0
github.com/robfig/cron/v3 v3.0.0
)

require (
github.com/gorilla/websocket v1.4.2 // indirect
golang.org/x/crypto v0.0.0-20210421170649-83a5a9bb288b // indirect
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68 // indirect
)
Brody
Brody14mo ago
godotenv 🤣
ThallesComH
ThallesComH14mo ago
main function
func main() {
dg, err := discordgo.New("Bot " + os.Getenv("token"))

if err != nil {
fmt.Println("Can't create a new client of Discord.", err)
return
}

dg.AddHandler(messageEditBday)
dg.AddHandler(BotReady)
err = dg.Open()

if err != nil {
fmt.Println("Can't open a connection with Discord.", err)
return
}

InitSlashCommands(dg)

searchBdayMessages(dg)

sc := make(chan os.Signal, 1)
signal.Notify(sc, syscall.SIGINT, syscall.SIGTERM, os.Interrupt, os.Kill)
<-sc

dg.Close()
}
func main() {
dg, err := discordgo.New("Bot " + os.Getenv("token"))

if err != nil {
fmt.Println("Can't create a new client of Discord.", err)
return
}

dg.AddHandler(messageEditBday)
dg.AddHandler(BotReady)
err = dg.Open()

if err != nil {
fmt.Println("Can't open a connection with Discord.", err)
return
}

InitSlashCommands(dg)

searchBdayMessages(dg)

sc := make(chan os.Signal, 1)
signal.Notify(sc, syscall.SIGINT, syscall.SIGTERM, os.Interrupt, os.Kill)
<-sc

dg.Close()
}
any alternative?
Brody
Brody14mo ago
railway
ThallesComH
ThallesComH14mo ago
what if im running on dev? on production i dont use godotenv btw
Brody
Brody14mo ago
dev environment
ThallesComH
ThallesComH14mo ago
cc @rokochi
rokochi
rokochi14mo ago
I'll try to get as close to this as possible (tomorrow...) Thanks so much
Want results from more Discord servers?
Add your server