Buttons not adding roles

^
52 Replies
d.js toolkit
d.js toolkit13mo ago
• What's your exact discord.js npm list discord.js and node node -v version? • Post the full error stack trace, not just the top part! • Show your code! • Explain what exactly your issue is. • Not a discord.js issue? Check out #useful-servers.
MrMythical
MrMythical13mo ago
getRole doesn't take an id and ids should be strings
SuperPEKKA336
SuperPEKKA33613mo ago
wot
MrMythical
MrMythical13mo ago
I think there are more things wrong here, because there should be an error if that code was even run
SuperPEKKA336
SuperPEKKA33613mo ago
. . . .
MrMythical
MrMythical13mo ago
because... button interactions dont have options
SuperPEKKA336
SuperPEKKA33613mo ago
wdym
grass
grass13mo ago
button interactions don’t have options
SuperPEKKA336
SuperPEKKA33613mo ago
?
Unknown User
Unknown User13mo ago
Message Not Public
Sign In & Join Server To View
SuperPEKKA336
SuperPEKKA33613mo ago
yes
Unknown User
Unknown User13mo ago
Message Not Public
Sign In & Join Server To View
SuperPEKKA336
SuperPEKKA33613mo ago
so im trying to create reaction roels but instead of using emojis using the buttons
Unknown User
Unknown User13mo ago
Message Not Public
Sign In & Join Server To View
SuperPEKKA336
SuperPEKKA33613mo ago
yeah
Unknown User
Unknown User13mo ago
Message Not Public
Sign In & Join Server To View
SuperPEKKA336
SuperPEKKA33613mo ago
so Google Bard gave me this:
const Discord = require('discord.js');

const client = new Discord.Client();

client.on('ready', () => {
// Get the channel ID where you want to send the embed.
const channelId = '1234567890';

// Create an embed object.
const embed = {
title: 'My Embed',
description: 'This is my embed.',
color: 0x0000FF,
};

// Add a button to the embed.
const button = {
type: 2,
style: 1,
label: 'Give me the role!',
custom_id: 'add_role',
action: {
type: 'addRole',
role_id: '8765432109',
},
};

// Set the action of the button to "addRole".
embed.components = [button];

// Set the role ID of the button.
button.role_id = '8765432109';

// Send the embed to the channel.
client.api.channels(channelId).messages.post({
embeds: [embed],
});
});

client.login('YOUR_BOT_TOKEN');
const Discord = require('discord.js');

const client = new Discord.Client();

client.on('ready', () => {
// Get the channel ID where you want to send the embed.
const channelId = '1234567890';

// Create an embed object.
const embed = {
title: 'My Embed',
description: 'This is my embed.',
color: 0x0000FF,
};

// Add a button to the embed.
const button = {
type: 2,
style: 1,
label: 'Give me the role!',
custom_id: 'add_role',
action: {
type: 'addRole',
role_id: '8765432109',
},
};

// Set the action of the button to "addRole".
embed.components = [button];

// Set the role ID of the button.
button.role_id = '8765432109';

// Send the embed to the channel.
client.api.channels(channelId).messages.post({
embeds: [embed],
});
});

client.login('YOUR_BOT_TOKEN');
Unknown User
Unknown User13mo ago
Message Not Public
Sign In & Join Server To View
SuperPEKKA336
SuperPEKKA33613mo ago
where? Google Bard
Unknown User
Unknown User13mo ago
Message Not Public
Sign In & Join Server To View
SuperPEKKA336
SuperPEKKA33613mo ago
its like ChatGPT but Google
Unknown User
Unknown User13mo ago
Message Not Public
Sign In & Join Server To View
SuperPEKKA336
SuperPEKKA33613mo ago
im just looking for examples
Unknown User
Unknown User13mo ago
Message Not Public
Sign In & Join Server To View
SuperPEKKA336
SuperPEKKA33613mo ago
no shit
Unknown User
Unknown User13mo ago
Message Not Public
Sign In & Join Server To View
SuperPEKKA336
SuperPEKKA33613mo ago
ok I just dont know JS too well
Unknown User
Unknown User13mo ago
Message Not Public
Sign In & Join Server To View
SuperPEKKA336
SuperPEKKA33613mo ago
SuperPEKKA336
SuperPEKKA33613mo ago
how would i do that?
Unknown User
Unknown User13mo ago
Message Not Public
Sign In & Join Server To View
SuperPEKKA336
SuperPEKKA33613mo ago
i can manage
MrMythical
MrMythical13mo ago
ehh, you should really brush up on your js
SuperPEKKA336
SuperPEKKA33613mo ago
ok\ so what is interaction a class?
Unknown User
Unknown User13mo ago
Message Not Public
Sign In & Join Server To View
SuperPEKKA336
SuperPEKKA33613mo ago
sorry
SuperPEKKA336
SuperPEKKA33613mo ago
discord.js Guide
Imagine a guide... that explores the many possibilities for your discord.js bot.
SuperPEKKA336
SuperPEKKA33613mo ago
line 19 thats where i got the interaction.isButton
Unknown User
Unknown User13mo ago
Message Not Public
Sign In & Join Server To View
SuperPEKKA336
SuperPEKKA33613mo ago
but i got it from the official guide?
Unknown User
Unknown User13mo ago
Message Not Public
Sign In & Join Server To View
SuperPEKKA336
SuperPEKKA33613mo ago
so wait the guide is wrong?
Unknown User
Unknown User13mo ago
Message Not Public
Sign In & Join Server To View
SuperPEKKA336
SuperPEKKA33613mo ago
wait nvm
Unknown User
Unknown User13mo ago
Message Not Public
Sign In & Join Server To View
SuperPEKKA336
SuperPEKKA33613mo ago
const member = interaction.options.getMember('target');
if (member.roles.cache.some(role => role.name === 'role name')) {
// ...
}
const member = interaction.options.getMember('target');
if (member.roles.cache.some(role => role.name === 'role name')) {
// ...
}
SuperPEKKA336
SuperPEKKA33613mo ago
discord.js Guide
Imagine a guide... that explores the many possibilities for your discord.js bot.
Unknown User
Unknown User13mo ago
Message Not Public
Sign In & Join Server To View
SuperPEKKA336
SuperPEKKA33613mo ago
when did I use it for buttons?
MrMythical
MrMythical13mo ago
Please stop trying to use djs without knowing how to use JS it benefits no one
Unknown User
Unknown User13mo ago
Message Not Public
Sign In & Join Server To View
SuperPEKKA336
SuperPEKKA33613mo ago
ah