support ephemeral command replies with missing pieces
This commit is contained in:
@@ -72,6 +72,34 @@ export class ReacordDiscordJs extends Reacord {
|
||||
initialContent,
|
||||
)
|
||||
}
|
||||
|
||||
override ephemeralReply(
|
||||
interaction: Discord.CommandInteraction,
|
||||
initialContent?: React.ReactNode,
|
||||
): ReacordInstance {
|
||||
return this.createInstance(
|
||||
new CommandReplyRenderer({
|
||||
type: "command",
|
||||
id: interaction.id,
|
||||
channelId: interaction.channelId,
|
||||
reply: async (options) => {
|
||||
await interaction.reply({
|
||||
...getDiscordMessageOptions(options),
|
||||
ephemeral: true,
|
||||
})
|
||||
return createEphemeralReacordMessage()
|
||||
},
|
||||
followUp: async (options) => {
|
||||
await interaction.followUp({
|
||||
...getDiscordMessageOptions(options),
|
||||
ephemeral: true,
|
||||
})
|
||||
return createEphemeralReacordMessage()
|
||||
},
|
||||
}),
|
||||
initialContent,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
function createReacordComponentInteraction(
|
||||
@@ -176,3 +204,20 @@ function createReacordMessage(message: Discord.Message): Message {
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
function createEphemeralReacordMessage(): Message {
|
||||
return {
|
||||
edit: () => {
|
||||
console.warn("Ephemeral messages can't be edited")
|
||||
return Promise.resolve()
|
||||
},
|
||||
disableComponents: () => {
|
||||
console.warn("Ephemeral messages can't be edited")
|
||||
return Promise.resolve()
|
||||
},
|
||||
delete: () => {
|
||||
console.warn("Ephemeral messages can't be deleted")
|
||||
return Promise.resolve()
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,6 +52,10 @@ export class ReacordTester extends Reacord {
|
||||
)
|
||||
}
|
||||
|
||||
override ephemeralReply(): ReacordInstance {
|
||||
return this.reply()
|
||||
}
|
||||
|
||||
async assertMessages(expected: ReturnType<this["sampleMessages"]>) {
|
||||
await nextTickPromise()
|
||||
expect(this.sampleMessages()).toEqual(expected)
|
||||
|
||||
@@ -28,6 +28,7 @@ export abstract class Reacord {
|
||||
|
||||
abstract send(...args: unknown[]): ReacordInstance
|
||||
abstract reply(...args: unknown[]): ReacordInstance
|
||||
abstract ephemeralReply(...args: unknown[]): ReacordInstance
|
||||
|
||||
protected handleComponentInteraction(interaction: ComponentInteraction) {
|
||||
for (const renderer of this.renderers) {
|
||||
|
||||
@@ -61,6 +61,21 @@ createCommandHandler(client, [
|
||||
reacord.reply(interaction, <FruitSelect />)
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "ephemeral-button",
|
||||
description: "button which shows ephemeral messages",
|
||||
run: (interaction) => {
|
||||
reacord.reply(
|
||||
interaction,
|
||||
<Button
|
||||
label="clic"
|
||||
onClick={() => {
|
||||
reacord.ephemeralReply(interaction, "you clic")
|
||||
}}
|
||||
/>,
|
||||
)
|
||||
},
|
||||
},
|
||||
])
|
||||
|
||||
await client.login(process.env.TEST_BOT_TOKEN)
|
||||
|
||||
2
test/ephemeral-reply.test.ts
Normal file
2
test/ephemeral-reply.test.ts
Normal file
@@ -0,0 +1,2 @@
|
||||
test.todo("ephemeral reply")
|
||||
export {}
|
||||
4
todo.md
4
todo.md
@@ -2,7 +2,7 @@
|
||||
|
||||
- [x] render to channel
|
||||
- [x] render to interaction
|
||||
- [ ] ephemeral messages
|
||||
- [x] ephemeral messages
|
||||
- [x] message content
|
||||
- embed
|
||||
- [x] color
|
||||
@@ -21,6 +21,8 @@
|
||||
- [x] select onChange
|
||||
- [x] action row
|
||||
- [x] button onClick
|
||||
- [ ] button click event
|
||||
- [ ] select change event
|
||||
- [x] deactivate
|
||||
- [x] destroy
|
||||
- [ ] docs
|
||||
|
||||
Reference in New Issue
Block a user