zdiscord icon indicating copy to clipboard operation
zdiscord copied to clipboard

Create a button that give role

Open CodexisPhantom opened this issue 2 years ago • 2 comments

Before submitting your question have you checked the check the FAQ or checked for similar issues already?: yes

Question: I want to create an embed with a button and when someone click the button he obtain a discord role. How can I do that ?

Information: FiveM artifact #: latest Using QBCore?: yes When did you last update QBCore if you are using it?: 4 days ago

CodexisPhantom avatar Jun 02 '22 07:06 CodexisPhantom

That's more under the scope of discord.js itself, but to point you in the right direction you'll need to write a custom handler to create the embed with button with a custom id ( Helpful guide for creating embeds with buttons ) then you'll need to modify the code in InteractionCreate.js along the lines of

if (interaction.isButton() && interaction.customId === "roleButton") { // "roleButton" needs to match whatever custom id you give the embed button when creating it
    // Give the person who clicked the button the role
    await interaction.member.roles.add("roleid");
    // Then some sort of feedback that it happened i guess
    return interaction.reply({ content: "Role added", ephemeral: true });
}

That's just a rough aproximation off the top of my head and hasn't been tested discord.js.org is your best source of help. They also have a discord https://discord.gg/djs

zfbx avatar Jun 02 '22 07:06 zfbx

Thx a lot, It's 6 months I don't code with discord.js and forgot how to do that.

CodexisPhantom avatar Jun 02 '22 08:06 CodexisPhantom