discord-friendly-components
v0.0.1
Published
A Nice Way To Save Data for a Button inside of a button (requires discord.js@dev version 13)
Downloads
1
Maintainers
Readme
Documentation
const ComponentFriend = require('../src/index');
const friend = new ComponentFriend("./save.json");
// the data you want to save
const data = {
"hello": "world"
}
// put the data you want to save in the first argument position
// returns the custom id that the data was saved under
const id = friend.CreateCustomID(data)
// take the id we created in the last example and put it inside the setCustomId
let button = new Discord.MessageButton()
.setCustomId(id)
.setLabel("Click Me")
.setStyle("SUCCESS");
message.channel.send("buttons!", { components: [ [button] ] });
client.on('interactionCreate', async (interaction) => {
// this will get the data we saved from above
const data = friend.GetCustomID(interaction.customId);
// now we should be able to send whatever text we saved in the "hello" property
await interaction.reply(data.hello);
});
//lets take the doc from above and just change it a bit
client.on('interactionCreate', async (interaction) => {
// this will get the data we saved from above
const data = friend.GetCustomID(interaction.customId);
// now we should be able to send whatever text we saved in the "hello" property
await interaction.reply({ content: data.hello, ephemeral: true });
// now when they call it again it'll change the message to say no
friend.EditCustomID(interaction.customId, { 'hello': 'no' })
});