R
Railway

✋|help

Deploying via github always crashes after 4-5 minutes

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

any alternative?
Bbrody1929/11/2023
railway
Tthallescomh9/11/2023
what if im running on dev?
on production i dont use godotenv btw
Bbrody1929/11/2023
dev environment
Tthallescomh9/11/2023
cc @rokochi
Rrokochi9/11/2023
I'll try to get as close to this as possible
(tomorrow...)
Thanks so much

Looking for more? Join the community!

Recommended Posts
Deploying bun 1.0in bun cause I don't need to build files is their somehow I can skip the build step since it alreadyWhere can you store Media Files?I'm using Django and have added a blog module to it where users can upload their own images. I was wEasy (?) shared variables questionThe environment contains the excellent Payload CMS template, attendant Mongo DB, and a Next.js frontPlan update issueIm having a issue with plan update. It just shows: Problem processing payment method and I triple cCan't create an account: Device requesting login is not supported. Please try again from a secure coTrying to create a new Railway Account, but getting this error: ```Device requesting login is not saccess to resource inside replicahi, when we setup an instance to have 2 replicas, how do we get the resource related to 1 of the reCommunicate between services with private networkProject ID: 3f51dcb4-6905-4a13-be75-4c6063e4324a I am trying to set up Railway to communicate betweWeb Server Not WorkingI just started a small simple web server. I generated a custom domain for now, and when trying to achttp://0.0.0.0:8000 to urlI am using a Django REST framework. When I query the URL at 0.0.0.0:8000 I can get a response, but aOpenSearch deploymentHi everyone. I require assistance with deploying an instance of OpenSearch since I get an error durUnable to connect with private networkHey guys, I'm a bit unsure on how to use the internal network. I have a .net api that has a privaterclone on railway to transfer data from one cloud to an other.Hello, I'm creating an app the requires to transfer data from one cloud storage (like onedrive to aBun 1.0 on railwayI am spinning up a simple bun app with 1 file in it. But for some reason all of my builds are failinSocket cannot be archivedWhen building the railway project I get a message saying that: /Users/x/Library/Application SupportBUN 1.0 + AstroHas anyone tried to deploy a Bun app yet? I am getting this error. ERROR: failed to solve: processDjango Railway admin consoleHi! I've had a really good time using Railway thus far, sea-change from setting up an EC2 instance Trouble sending emails via SMTPprojectId: `bb66f5c0-53f9-4e9f-b11f-5965f5d6ec74` serviceId: `b3029692-b78a-4487-bcb0-44e001afecb8` Cannot have a TCP proxy and a domainWhen trying to create a service with a proxy, I'm getting this error. Can I not have a TCP proxy serChange region for Postgres DatabaseHey ! Congratulations for the launch of deployment region ! Now, how can I migrate my db to another Connection Pooling or PgBouncer for Postgres Instances?Hello! Anyone know if the Railway Postgres instance has any sort of connection pooling or pgBouncer?