fix(bots/discord): replace use of deprecated options.ephemeral in replies

This commit is contained in:
PalmDevs
2025-04-16 20:33:09 +07:00
parent 4e797a2cfd
commit 31e5cf7fc5
15 changed files with 56 additions and 27 deletions

View File

@@ -2,7 +2,7 @@ import { unlinkSync, writeFileSync } from 'fs'
import { join } from 'path'
import { inspect } from 'util'
import { createContext, runInContext } from 'vm'
import { ApplicationCommandOptionType } from 'discord.js'
import { ApplicationCommandOptionType, MessageFlags } from 'discord.js'
import { AdminCommand } from '$/classes/Command'
import { createSuccessEmbed } from '$/utils/discord/embeds'
@@ -85,8 +85,8 @@ export default new AdminCommand({
})
await trigger.reply({
ephemeral: true,
embeds: [embed],
flags: MessageFlags.Ephemeral,
files,
})

View File

@@ -1,4 +1,5 @@
import { AdminCommand } from '$/classes/Command'
import { type CommandInteraction, MessageFlags } from 'discord.js'
export default new AdminCommand({
name: 'reload',
@@ -10,7 +11,7 @@ export default new AdminCommand({
logger.debug('Invalidating previous config...')
context.config.invalidate()
if ('deferReply' in trigger) await trigger.deferReply({ ephemeral: true })
if ((trigger as CommandInteraction).deferReply) await trigger.deferReply({ flags: MessageFlags.Ephemeral })
logger.info('Reinitializing API client to reload configuration...')
await api.client.ws.setOptions(

View File

@@ -1,4 +1,5 @@
import { AdminCommand } from '$/classes/Command'
import { MessageFlags } from 'discord.js'
export default new AdminCommand({
name: 'stop',
@@ -9,7 +10,7 @@ export default new AdminCommand({
logger.fatal('Stopping bot...')
trigger.reply({
content: 'Stopping... (I will go offline once done)',
ephemeral: true,
flags: MessageFlags.Ephemeral,
})
if (!api.client.disconnected) api.client.disconnect()

View File

@@ -1,4 +1,4 @@
import { EmbedBuilder } from 'discord.js'
import { EmbedBuilder, MessageFlags } from 'discord.js'
import Command from '$/classes/Command'
import { applyCommonEmbedStyles } from '$/utils/discord/embeds'
@@ -18,6 +18,7 @@ export default new Command({
const reply = await trigger
.reply({
embeds: [embed.toJSON()],
flags: MessageFlags.Ephemeral,
})
.then(it => it.fetch())

View File

@@ -1,5 +1,5 @@
import CommandError, { CommandErrorType } from '$/classes/CommandError'
import { ApplicationCommandOptionType, Message } from 'discord.js'
import { ApplicationCommandOptionType, Message, MessageFlags } from 'discord.js'
import { ModerationCommand } from '../../classes/Command'
export default new ModerationCommand({
@@ -40,7 +40,7 @@ export default new ModerationCommand({
await trigger.reply({
content: 'OK!',
ephemeral: true,
flags: MessageFlags.Ephemeral,
})
},
})

View File

@@ -1,6 +1,7 @@
import { ModerationCommand } from '$/classes/Command'
import { createSuccessEmbed } from '$/utils/discord/embeds'
import { cureNickname } from '$/utils/discord/moderation'
import { MessageFlags } from 'discord.js'
export default new ModerationCommand({
name: 'cure',
@@ -18,7 +19,7 @@ export default new ModerationCommand({
await cureNickname(member)
await interaction.reply({
embeds: [createSuccessEmbed(null, `Cured nickname for ${member.toString()}`)],
ephemeral: true,
flags: MessageFlags.Ephemeral,
})
},
})

View File

@@ -2,7 +2,7 @@ import Command from '$/classes/Command'
import CommandError, { CommandErrorType } from '$/classes/CommandError'
import { createSuccessEmbed } from '$/utils/discord/embeds'
import type { ConfigMessageScanResponseLabelConfig } from 'config.schema'
import type { FetchMessageOptions, MessageResolvable } from 'discord.js'
import { type FetchMessageOptions, MessageFlags, type MessageResolvable } from 'discord.js'
import { config } from '../../../context'
const msRcConfig = config.messageScan?.humanCorrections?.allow
@@ -70,7 +70,7 @@ export default new Command({
`The provided message has been trained as \`${label}\`. Thank you for your contribution!`,
),
],
ephemeral: true,
flags: MessageFlags.Ephemeral,
})
},
})

View File

@@ -1,7 +1,7 @@
import Command from '$/classes/Command'
import CommandError, { CommandErrorType } from '$/classes/CommandError'
import type { ConfigMessageScanResponseLabelConfig } from 'config.schema'
import { type APIStringSelectComponent, ComponentType } from 'discord.js'
import { type APIStringSelectComponent, ComponentType, MessageFlags } from 'discord.js'
import { config } from '../../../context'
const msRcConfig = config.messageScan?.humanCorrections?.allow
@@ -44,7 +44,7 @@ export default new Command({
type: ComponentType.ActionRow,
},
],
ephemeral: true,
flags: MessageFlags.Ephemeral,
})
},
})

View File

@@ -1,6 +1,7 @@
import CommandError from '$/classes/CommandError'
import { createStackTraceEmbed } from '$utils/discord/embeds'
import { on, withContext } from '$utils/discord/events'
import { MessageFlags } from 'discord.js'
withContext(on, 'interactionCreate', async (context, interaction) => {
if (!interaction.isChatInputCommand()) return
@@ -20,7 +21,7 @@ withContext(on, 'interactionCreate', async (context, interaction) => {
await interaction[interaction.replied ? 'followUp' : 'reply']({
embeds: [err instanceof CommandError ? err.toEmbed() : createStackTraceEmbed(err)],
ephemeral: true,
flags: MessageFlags.Ephemeral,
})
// 100 and up are user errors

View File

@@ -1,6 +1,7 @@
import CommandError from '$/classes/CommandError'
import { createStackTraceEmbed } from '$utils/discord/embeds'
import { on, withContext } from '$utils/discord/events'
import { MessageFlags } from 'discord.js'
withContext(on, 'interactionCreate', async (context, interaction) => {
if (!interaction.isContextMenuCommand()) return
@@ -20,7 +21,7 @@ withContext(on, 'interactionCreate', async (context, interaction) => {
logger.error(`Error while executing command ${interaction.commandName}:`, err)
await interaction[interaction.replied ? 'followUp' : 'reply']({
embeds: [err instanceof CommandError ? err.toEmbed() : createStackTraceEmbed(err)],
ephemeral: true,
flags: MessageFlags.Ephemeral,
})
}
})

View File

@@ -3,7 +3,12 @@ import { handleUserResponseCorrection } from '$/utils/discord/messageScan'
import { createErrorEmbed, createStackTraceEmbed, createSuccessEmbed } from '$utils/discord/embeds'
import { on, withContext } from '$utils/discord/events'
import type { ButtonInteraction, StringSelectMenuInteraction, TextBasedChannel } from 'discord.js'
import {
type ButtonInteraction,
MessageFlags,
type StringSelectMenuInteraction,
type TextBasedChannel,
} from 'discord.js'
import { eq } from 'drizzle-orm'
// No permission check required as it is already done when the user reacts to a bot response
@@ -26,7 +31,7 @@ withContext(on, 'interactionCreate', async (context, interaction) => {
if (!response)
return void (await interaction.reply({
content: "I don't recall having sent this response, so I cannot correct it.",
ephemeral: true,
flags: MessageFlags.Ephemeral,
}))
try {
@@ -91,7 +96,7 @@ withContext(on, 'interactionCreate', async (context, interaction) => {
logger.error('Failed to handle correct response interaction:', e)
await interaction.reply({
embeds: [createStackTraceEmbed(e)],
ephemeral: true,
flags: MessageFlags.Ephemeral,
})
}
})

View File

@@ -1,7 +1,6 @@
import { createErrorEmbed, createStackTraceEmbed, createSuccessEmbed } from '$utils/discord/embeds'
import { on, withContext } from '$utils/discord/events'
import type { TextBasedChannel } from 'discord.js'
import { MessageFlags, type TextBasedChannel } from 'discord.js'
withContext(on, 'interactionCreate', async (context, interaction) => {
const {
@@ -28,7 +27,7 @@ withContext(on, 'interactionCreate', async (context, interaction) => {
'Thank you for your contribution! Unfortunately, the message could not be found.',
),
],
ephemeral: true,
flags: MessageFlags.Ephemeral,
}))
const selectedLabel = interaction.values[0]!
@@ -40,13 +39,13 @@ withContext(on, 'interactionCreate', async (context, interaction) => {
`Thank you for your contribution! The selected message is being trained as \`${selectedLabel}\`. 🎉`,
),
],
ephemeral: true,
flags: MessageFlags.Ephemeral,
})
} catch (e) {
logger.error('Failed to handle train message interaction:', e)
await interaction.reply({
embeds: [createStackTraceEmbed(e)],
ephemeral: true,
flags: MessageFlags.Ephemeral,
})
}
})