bwmarrin / discordgo

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

Is there a way to select and delete already existing messages is a channel? #872

Closed Stegosawr closed 3 years ago

Stegosawr commented 3 years ago

I was wondering if there is a way to delete already existing messages of a channel in discord via a discordgo bot. Meaning you can get existing messages via a function and delete them.

CarsonHoffman commented 3 years ago

https://pkg.go.dev/github.com/bwmarrin/discordgo#Session.ChannelMessageDelete

Stegosawr commented 3 years ago

As refered to here https://gowalker.org/github.com/bwmarrin/discordgo#Session_ChannelDelete this only works for messages that are created after the bot is started, right? Because of the state?

CarsonHoffman commented 3 years ago

No. It will work for any message—the function is simply a shallow wrapper over the HTTP endpoint. There is no state involved.

Stegosawr commented 3 years ago

But how are you suposed to get the existing messages? I tried using the Channel type and thats the point https://gowalker.org/github.com/bwmarrin/discordgo#Channel where I am having trouble selecting the already existing messages is there a better way? Sorry for not being specific in the first message.

CarsonHoffman commented 3 years ago

It sounds like your question fundamentally relates to retrieving messages rather than deleting them, then. If you'd like to pull messages from a channel that don't exist in the state, you can use (*Session).ChannelMessages. You need to decide how you actually want to determine what message(s) you want to delete, however—is it just the fact that it appeared in a channel? is it mentioned by a user in a command? is it replied to by another message? etc. These aren't necessarily questions I'm asking directly to you, but things to ponder: you can't fight the second law of thermodynamics—you can't produce information where there is none. You need some sort of tie to that message.

Stegosawr commented 3 years ago

It might be late already, but not late enough for me to question general physic laws. But I guess you already help a lot. Thank you very much for that.