Skip to content

Commit

Permalink
feat(moderation): option to delete polls automatically
Browse files Browse the repository at this point in the history
At least until Discord finally allows server owners to disable this feature.
  • Loading branch information
Pkmmte committed Apr 11, 2024
1 parent 654ef21 commit 5aea548
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/thin-dryers-marry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@robojs/moderation': patch
---

feat: option to delete polls automatically
24 changes: 24 additions & 0 deletions packages/plugin-modtools/src/events/_start.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import type { Client, TextChannel } from 'discord.js'

interface PluginOptions {
deletePolls?: boolean
}

export default (client: Client, options: PluginOptions) => {
const { deletePolls } = options

client.on('raw', async (event) => {
// Only listen to new message events
if (!deletePolls || event.t !== 'MESSAGE_CREATE') {
return
}

// Delete poll messages
const { d: message } = event

if (message.poll) {
const channel = client.channels.cache.get(message.channel_id) as TextChannel
channel?.messages.delete(message.id)
}
})
}

0 comments on commit 5aea548

Please sign in to comment.