Interaction Managing Duty

Hello, i'm making message & interaction manager system and got wonder why the interaction should requires to edit/add/remove the message. Should I respond only via interaction object for interaction? Can't I just give a surplus response to the discord? Do I have to change the message?
15 Replies
d.js toolkit
d.js toolkit15mo ago
- What's your exact discord.js npm list discord.js and node node -v version? - Not a discord.js issue? Check out #other-js-ts. - Consider reading #how-to-get-help to improve your question! - Explain what exactly your issue is. - Post the full error stack trace, not just the top part! - Show your code! - Issue solved? Press the button!
sharlotte
sharlotteOP15mo ago
RealTimeRPG@ C:\Users\user\Documents\GitHub\RealTimeRPG
├─┬ @discordx/[email protected]
└── [email protected] deduped
├─┬ @discordx/[email protected]
└── [email protected] deduped
└── [email protected] deduped
RealTimeRPG@ C:\Users\user\Documents\GitHub\RealTimeRPG
├─┬ @discordx/[email protected]
└── [email protected] deduped
├─┬ @discordx/[email protected]
└── [email protected] deduped
└── [email protected] deduped
and node version is v18.13.0. but i think you don't need to know about these because this is about not to implementions - but just abstract solution about managing interaction. for an example, if a button is clicked, the discord bot will run some logic which depends on that button clicking. but sometimes the discord bot doesn't want to response anything to the message. or there are no way to response, for example in my case, i want to reply interaction in another thread channel - not exactly same channel where the message is in.
Dagan
Dagan15mo ago
I think that this is a good solution: - DeferReply - DeleteReply - Send a message in another thread channel
sharlotte
sharlotteOP15mo ago
* deferReply is for reacting to message later, not for dismiss. isn't it? * deleteReply is out of the context. deleting reply is not wanted situation for every case. * Sending a message in another channel - yes, that's what i exact have done.
// ignore the interaction field - that's out of the context
public async send(channel: Discord.TextBasedChannel | null = this.interaction.channel): Promise<Discord.Message> {
if (!channel) throw new Error("channel does not exist");
const options: Discord.MessageCreateOptions = {
content: this.content,
embeds: this.embeds,
components: this.components,
files: this.files,
};
const sent = await channel.send(options);
this.message = sent;
return sent;
}
// ignore the interaction field - that's out of the context
public async send(channel: Discord.TextBasedChannel | null = this.interaction.channel): Promise<Discord.Message> {
if (!channel) throw new Error("channel does not exist");
const options: Discord.MessageCreateOptions = {
content: this.content,
embeds: this.embeds,
components: this.components,
files: this.files,
};
const sent = await channel.send(options);
this.message = sent;
return sent;
}
but as you see, this is not replying to interaction. this is just creating new message to given channel.
Squid
Squid15mo ago
Generally, the "best" solution is an ephemeral reply saying something like "the message was sent successfully!". You may also need to reply if there are any errors with sending the message in the chosen channel, like if your bot is missing access/permissions, and that can be told via an interaction reply Discord expects you to reply to every interaction for good user experience, and the rest of us devs just have to accept that expectation
Dagan
Dagan15mo ago
Well you can deferReply and edit the reply if you want to send back feedback or delete it if you don't If you defer and delete Discord won't say 'this interaction wasn't responded) Or someh like that
sharlotte
sharlotteOP15mo ago
ah, that was some steps! i thought that was choices
Dagan
Dagan15mo ago
It was steps Yeah Srry, i didn't make it 1. 2. 3. Because you can send the message before deleting the reply But you can also do it the other way around So 1. Was needed but 2 and 3 could be switched But does this help? Or do you want something else
sharlotte
sharlotteOP15mo ago
well, i tried (1 -> 2), 3 at the same time with ephemeral reply. this still require to send the message but feels better! thanks for your answers
public async send(channel: Discord.TextBasedChannel | null = this.interaction.channel): Promise<Discord.Message> {
if (!channel) throw new Error("channel does not exist");
const options: Discord.MessageCreateOptions = {
content: this.content,
embeds: this.embeds,
components: this.components,
files: this.files,
};
// actually doesn't need to await.
(async () => {
if (this.interaction.isRepliable()) {
await this.interaction.deferReply({ ephemeral: true });
this.interaction.deleteReply();
}
})();
const sent = await channel.send(options);
this.message = sent;
return sent;
}
public async send(channel: Discord.TextBasedChannel | null = this.interaction.channel): Promise<Discord.Message> {
if (!channel) throw new Error("channel does not exist");
const options: Discord.MessageCreateOptions = {
content: this.content,
embeds: this.embeds,
components: this.components,
files: this.files,
};
// actually doesn't need to await.
(async () => {
if (this.interaction.isRepliable()) {
await this.interaction.deferReply({ ephemeral: true });
this.interaction.deleteReply();
}
})();
const sent = await channel.send(options);
this.message = sent;
return sent;
}
Dagan
Dagan15mo ago
Wait, i don't think you can delete an ephemeral msg
sharlotte
sharlotteOP15mo ago
i know user can delete the message but that makes user to be tired. so let it be deleted automatically
Dagan
Dagan15mo ago
No, it's not allowed To delete ephemeral msg Wait I'll look in the docs
sharlotte
sharlotteOP15mo ago
No description
sharlotte
sharlotteOP15mo ago
well, it works.
Dagan
Dagan15mo ago
Oh, okay Then i remembered it wrong
Want results from more Discord servers?
Add your server