Hacker News new | past | comments | ask | show | jobs | submit login
Building a Discord bot in Rust (shuttle.rs)
81 points by dohguy on Sept 29, 2022 | hide | past | favorite | 13 comments



I did a small discord bot 4-5 months ago with serenity, and while it worked, I found it was a mess.

It felt like someone was trying to force functional programming on rust, with typenames from java.

Sure it works but the code looked very verbose, and the ridiculous types like 'ApplicationCommandInteractionDataOptionValue' definitely did not help.

Serenity works well, it's just definitely not rust-style.


The type in question has since been renamed to CommandDataOption, as well as other such long types (https://github.com/serenity-rs/serenity/pull/1899).

With forced functional programming, you may be referring to serenity's builders? For example

    .send_message(|m| m
        .content("text")
        .embed(|e| e
            .description("...")
            .timestamp("...")
        )
        .components(|c| c
            .create_action_row(|r| r
                .create_button(|b| b
                    .style(ButtonStyle::Primary)
                    .label("press me")
                    .custom_id("button1")
                )
            )
        )
    ).await?;
In the next breaking release (`next` branch in git), we have a new by-value builder style which has turned out to be a better design in many ways:

    .send_message(CreateMessage::new()
        .content("text")
        .embed(CreateEmbed::new()
            .description("...")
            .timestamp("...")
        )
        .components(CreateComponents::new()
            .add_action_row(CreateActionRow::new()
                .add_button(
                    CreateButton::new(ButtonStyle::Primary, "button1").label("press me")
                )
            )
        )
    )
And a PR is open to make the API even better (replace redundant CreateComponents with Vec<CreateActionRow>) and more will be coming presumably.

Does this seem more rusty to you? We're open to more criticism - developmenet on serenity is quite active currently (e.g. 52 PRs merged in the last month)


The word you're looking for is 'idiomatic'


You might like Twilight[1]. It is a smaller project, but a lot more modular and "rusty".

[1]: https://github.com/twilight-rs/twilight


shuttle has released support for Serenity (a Rust library for the Discord API) a while back and now we have a tutorial ready for anyone willing to give it a go: https://www.shuttle.rs/blog/2022/09/14/serentity-discord-bot (creating a simple Discord bot, extending it to a weather forecast bot and deploying it with shuttle, for free).

To give you some context on shuttle; it is a Rust-native cloud development platform (open-source) that allows you to deploy your Rust app (or Discord bot, in this case) by adding a single annotation to your main file. Once you do that, you can run `cargo shuttle deploy` and your app/bot is all set!


This looks really cool! I've written a music bot with Serenity before and have been hosting it on a VPS. I was looking on migrating to serverless infra, but Cloudflare workers sadly didn't work with streaming audio over a voice channel for a sustained period. Is this use case supported by Shuttle?


One thing that would help me have confidence in shuttle would be pricing somewhere between the $0 and "ask us" tiers. Something to consider after exiting your alpha.

I suppose that's what the "host for yourself on AWS" approach is for, it would be great to see some docs written for that too!

This is neat. I'm a huge fan of serverless as a backend. I happen to enjoy writing JavaScript, so my needs are fairly well meet, but I'm increasingly using rust for side projects so I'm glad to see someone taking the time to make it easy to use and deploy in a serverless environment.


Hey socialismisok!

I totally get your point regarding pricing.

Our current pricing model is currently in progress and we are shaping our billing around the needs of our users while we are in alpha. This is subject to change in the near future depending on how shuttle evolves over the next couple of weeks/months.

And thank you for the feedback re: AWS approach being documented, this is definitely something that we'll cover in the near future.

Glad you like it! :) Lmk if you have any other questions.


Please. Don't use Rust other than systems programming. Just use Go or Python for anything else.


How does the performance of shuttle compare to self-hosting on e.g. AWS?


Hey surrTurr,

shuttle is on AWS under the hood although we make the process much easier for people (not having to deal with the console and other its and bits). There is (almost) no runtime penalty in using shuttle, vs deploying this yourself.

Other than that, we've got GH actions you can use, you get GitOps for free, you don't have to write Containerfiles and we have a centralised build system which will reduce build time by hitting the cache!

Lmk if you have any other questions :)


Does shuttle support something like Redis for caching?


For now, we offer the persist feature. We allow you to store and load structs that can be serializable with serde.

Redis is a highly sought feature which we'll be aiming to implement in the near future! :)




Consider applying for YC's Fall 2025 batch! Applications are open till Aug 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: