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