bwmarrin / discordgo

(Golang) Go bindings for Discord
BSD 3-Clause "New" or "Revised" License
5.05k stars 802 forks source link

Only `ApplicationCommand` takes `DescriptionLocalizations` as a pointer #1555

Open leonlarsson opened 1 month ago

leonlarsson commented 1 month ago

I am working to port a Discord bot to Go, and I noticed this potential issue.

While building out my slash command data, I noticed that ApplicationCommand is the only struct that takes {Name/Description}Localizations as a pointer. This makes life a little harder as I have a function building this for me. I found this comment on the localization PR: https://github.com/bwmarrin/discordgo/pull/1143#discussion_r1156460628

My question is the same as the one above: Why does ApplicationCommand take a pointer while ApplicationCommandOption and ApplicationCommandOptionChoice doesn't?

My current code with the required workaround (assigning a variable):

func GetCommands() []*discordgo.ApplicationCommand {
    // Workaround
    descriptionLocations := localization.BuildDiscordLocalizations("slash_commands/base/bf2042_description")
    return []*discordgo.ApplicationCommand{
        {
            Name:                     "bf2042",
            Description:              localization.GetEnglishString("slash_commands/base/bf2042_description"),
            DescriptionLocalizations: &descriptionLocations,
            Options: []*discordgo.ApplicationCommandOption{
                {
                    Name:                     localization.GetEnglishString("slash_commands/stats/name"),
                    NameLocalizations:        localization.BuildDiscordLocalizations("slash_commands/stats/name"),
                    Description:              localization.GetEnglishString("slash_commands/stats/bf2042_description"),
                    DescriptionLocalizations: localization.BuildDiscordLocalizations("slash_commands/stats/bf2042_description"),

Disclaimer: I am very new to Go. I would appreciate the help :)