Buttons not adding roles

^
52 Replies
d.js toolkit
d.js toolkit2y 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
MrMythical2y ago
getRole doesn't take an id and ids should be strings
SuperPEKKA336
SuperPEKKA336OP2y ago
wot
MrMythical
MrMythical2y ago
I think there are more things wrong here, because there should be an error if that code was even run
SuperPEKKA336
SuperPEKKA336OP2y ago
. . . .
MrMythical
MrMythical2y ago
because... button interactions dont have options
SuperPEKKA336
SuperPEKKA336OP2y ago
wdym
grass
grass2y ago
button interactions don’t have options
SuperPEKKA336
SuperPEKKA336OP2y ago
?
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
SuperPEKKA336
SuperPEKKA336OP2y ago
yes
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
SuperPEKKA336
SuperPEKKA336OP2y ago
so im trying to create reaction roels but instead of using emojis using the buttons
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
SuperPEKKA336
SuperPEKKA336OP2y ago
yeah
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
SuperPEKKA336
SuperPEKKA336OP2y 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 User2y ago
Message Not Public
Sign In & Join Server To View
SuperPEKKA336
SuperPEKKA336OP2y ago
where? Google Bard
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
SuperPEKKA336
SuperPEKKA336OP2y ago
its like ChatGPT but Google
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
SuperPEKKA336
SuperPEKKA336OP2y ago
im just looking for examples
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
SuperPEKKA336
SuperPEKKA336OP2y ago
no shit
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
SuperPEKKA336
SuperPEKKA336OP2y ago
ok I just dont know JS too well
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
SuperPEKKA336
SuperPEKKA336OP2y ago
SuperPEKKA336
SuperPEKKA336OP2y ago
how would i do that?
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
SuperPEKKA336
SuperPEKKA336OP2y ago
i can manage
MrMythical
MrMythical2y ago
ehh, you should really brush up on your js
SuperPEKKA336
SuperPEKKA336OP2y ago
ok\ so what is interaction a class?
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
SuperPEKKA336
SuperPEKKA336OP2y ago
sorry
SuperPEKKA336
SuperPEKKA336OP2y ago
discord.js Guide
Imagine a guide... that explores the many possibilities for your discord.js bot.
SuperPEKKA336
SuperPEKKA336OP2y ago
line 19 thats where i got the interaction.isButton
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
SuperPEKKA336
SuperPEKKA336OP2y ago
but i got it from the official guide?
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
SuperPEKKA336
SuperPEKKA336OP2y ago
so wait the guide is wrong?
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
SuperPEKKA336
SuperPEKKA336OP2y ago
wait nvm
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
SuperPEKKA336
SuperPEKKA336OP2y 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
SuperPEKKA336OP2y ago
discord.js Guide
Imagine a guide... that explores the many possibilities for your discord.js bot.
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
SuperPEKKA336
SuperPEKKA336OP2y ago
when did I use it for buttons?
MrMythical
MrMythical2y ago
Please stop trying to use djs without knowing how to use JS it benefits no one
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
SuperPEKKA336
SuperPEKKA336OP2y ago
ah
Want results from more Discord servers?
Add your server