bwmarrin / discordgo

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

Channel Categories/Groups Missing #495

Closed Zamiell closed 6 years ago

Zamiell commented 6 years ago

Hello; this is an excellent library, and thanks so much for providing it.

Does this library allow me to create channels INTO a channel category/group?

I see that the GuildChannelCreate(guildID, name, ctype string) function creates channels without ANY category attached to them.

Or is there a way with this library to move an existing channel into a category/group? Because then I can just do a two step process.

Seklfreak commented 6 years ago

You should be able to add an existing channel to a category using the newly added ChannelEditComplex function (ParentID).

Zamiell commented 6 years ago

Ah, I see, its on the "develop" branch. Thank you @Seklfreak , I'll try it out!

Seklfreak commented 6 years ago

You should probably always use the develop branch. master doesn't get updated very often, and develop is stable enough.

Zamiell commented 6 years ago

Through trial and error, I've found that I can query the Discord API directly by myself using curl in order to get the ID of the category from the parent_id parameter:

curl --header "Authorization: Bot [key]" https://discordapp.com/api/channels/392872395116904448
{"guild_id": "392182453248458762", "name": "r-1-zamiel-vs-xunhingedmoose", "permission_overwrites": [], "topic": null, "parent_id": "392884552407711744", "nsfw": false, "position": 5, "last_message_id": "392872395381276682", "type": 0, "id": "392872395116904448"}

Ideally, I'd like to be able to use the DiscordGo library to enumerate through all of the categories on a server so that I can find the ID programmatically without having to do this process manually. Is that possible?

Seklfreak commented 6 years ago

If you are using the develop branch you can access a channels parent id:

channel, err := session.State.Channel("392872395116904448")
fmt.Println(channel.ParentID)

you can then get the get the parent channel from the state

parent, err := session.State.Channel(channel.ParentID)
fmt.Println(parent.Name)
Zamiell commented 6 years ago

@Seklfreak Are all channel categories just channels themselves?

Seklfreak commented 6 years ago

You can find the name of an existing category from it's ID using session.State.Channel(channelID), no need to iterate over all categories.

But here is how to iterate over all categories:

guild, err := session.State.Guild("392182453248458762")
for _, guildChannel := range guild.Channels {
    if guildChannel.Type == discordgo.ChannelTypeGuildCategory {
        fmt.Println(guildChannel.Name)
    }
}
Zamiell commented 6 years ago

Thank you! I see now that all categories are just channels themselves, which is kind of confusing at first, but makes sense.

Seklfreak commented 6 years ago

@Zamiell I think this issue can be closed. :)

Zamiell commented 6 years ago

It might be best to close it when the change gets merged into master?

Seklfreak commented 6 years ago

Oh, maybe, I don't know to be honest. 🤔

Zamiell commented 6 years ago

@bwmarrin Can you put it on master?

bwmarrin commented 6 years ago

It will be, fairly soon.