Lucas Coacci
Lucas Coacci

Reputation: 1

Delete all messages from a channel using Discord

I'm trying to delete all messages from a channel using discord bot, but the only command to delete messages that i found is s.ChannelMessageDelete(m.ChannelID, m.ID)

it only deletes 1 message at time, i would like to clear all which command can i use to do it?

Upvotes: 0

Views: 602

Answers (1)

cam
cam

Reputation: 5228

EDIT As the commenter noted, you can see this will only delete 100 messages at a time in the source code. If you want to delete all messages, you'll have to call this function in chunks of 100 messages.

From the source code and the docs, you can use ChannelMessagesBulkDelete:

// ChannelMessagesBulkDelete bulk deletes the messages from the channel for the provided messageIDs.
// If only one messageID is in the slice call channelMessageDelete function.
// If the slice is empty do nothing.
// channelID : The ID of the channel for the messages to delete.
// messages  : The IDs of the messages to be deleted. A slice of string IDs. A maximum of 100 messages.
func (s *Session) ChannelMessagesBulkDelete(channelID string, messages []string) (err error) {
   ...
}

Upvotes: 1

Related Questions