Looking to create a Discord bot in TypeScript and wanting to disable two buttons when one is clicked, but unsure how to accomplish this.
This is my command with the two buttons (warn.ts):
import {
PermissionsBitField,
ButtonBuilder,
ActionRowBuilder,
ButtonStyle,
SlashCommandBuilder,
APIInteractionDataResolvedGuildMember,
GuildMember
} from 'discord.js';
import { SlashCommand } from '../clientdata';
import { error, response, rspComponents, logs } from '../utils/embed';
const admin = require('firebase-admin');
let db = admin.firestore();
const isGuildMember = (obj: GuildMember | APIInteractionDataResolvedGuildMember | null): obj is GuildMember => {
return obj !== null && 'id' in obj;
};
export const command: SlashCommand = {
name: 'warn',
data: new SlashCommandBuilder()
.setName('warn')
.setDescription("Permet d'ajouter un avertissement à un utilisateur")
.addUserOption(option => option.setName('user').setDescription('Utilisateur à avertir').setRequired(true))
.addStringOption(option => option.setName('reason').setDescription("Description de l'avertissement").setRequired(true))
.setDefaultMemberPermissions(PermissionsBitField.Flags.BanMembers),
execute: async interaction => {
const { options, member } = interaction;
const user = options.getMember('user');
const reason = options.getString('reason');
if (reason === null) {
return;
//to do
}
if (!isGuildMember(user)) {
return;
//to do
}
// Rest of the code remains unchanged...
}
};
This is my file for handling interactions (interactionCreate.ts):
import { BotEvent, isChatInputCommand } from '../clientdata';
import { Events, Interaction } from 'discord.js';
import { clientData } from '../clientdata';
// Code remains unchanged...
And this is my file for controlling the button behavior (cancel.ts):
import { Buttons } from '../clientdata';
import { error } from '../utils/embed';
export const button: Buttons = {
name: 'False',
execute: async interaction => {
interaction.component.disabled;
error(interaction, `❌ Le warn à était annulé.`);
}
};
I attempted adding interaction.component.disabled;
in my cancel.ts file to disable the button, but it did not work as expected.
import { Buttons } from '../clientdata';
import { error } from '../utils/embed';
// Code remains unchanged...