Why add role says invalidtype

const { SlashCommandBuilder, PermissionFlagsBits } = require('discord.js');
const { teamchanegeChannelID, CCroelId } = require('../../config/plugins/promote.json')
module.exports = {
data: new SlashCommandBuilder()
.setName('promote')
.setDescription('Select a member and promote them.')
.addUserOption(option =>
option
.setName('target')
.setDescription('The member to promote')
.setRequired(true))
.addStringOption(option =>
option
.setName('position')
.setDescription('The position for pormoting')
.setRequired(true)
.addChoices(
{ name: 'Convoy Control', value: 'CC' },
{ name: 'Driver', value: 'Driver' },
{ name: 'Driver Trainee', value: 'Trainee' },
))
.setDefaultMemberPermissions(PermissionFlagsBits.ManageRoles)
.setDMPermission(false),
async execute(interaction) {
const member = interaction.options.getMember('target');
member.roles.add(CCroelId);
},
};
const { SlashCommandBuilder, PermissionFlagsBits } = require('discord.js');
const { teamchanegeChannelID, CCroelId } = require('../../config/plugins/promote.json')
module.exports = {
data: new SlashCommandBuilder()
.setName('promote')
.setDescription('Select a member and promote them.')
.addUserOption(option =>
option
.setName('target')
.setDescription('The member to promote')
.setRequired(true))
.addStringOption(option =>
option
.setName('position')
.setDescription('The position for pormoting')
.setRequired(true)
.addChoices(
{ name: 'Convoy Control', value: 'CC' },
{ name: 'Driver', value: 'Driver' },
{ name: 'Driver Trainee', value: 'Trainee' },
))
.setDefaultMemberPermissions(PermissionFlagsBits.ManageRoles)
.setDMPermission(false),
async execute(interaction) {
const member = interaction.options.getMember('target');
member.roles.add(CCroelId);
},
};
4 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.
Unicorn.
Unicorn.OP2y ago
├── [email protected] ├── [email protected] ├── [email protected] └── [email protected]
E:\htcqq\Desktop\Federal-Transport-Bot-1.2\node_modules\discord.js\src\managers\GuildMemberRoleManager.js:124
throw new DiscordjsTypeError(
^

TypeError [InvalidType]: Supplied roles is not a Role, Snowflake or Array or Collection of Roles or Snowflakes.
at GuildMemberRoleManager.add (E:\htcqq\Desktop\Federal-Transport-Bot-1.2\node_modules\discord.js\src\managers\GuildMemberRoleManager.js:124:15)
at Object.execute (E:\htcqq\Desktop\Federal-Transport-Bot-1.2\commands\slash\promote.js:26:16)
at Object.execute (E:\htcqq\Desktop\Federal-Transport-Bot-1.2\events\guild\interactioncreate.js:16:18)
at Client.<anonymous> (E:\htcqq\Desktop\Federal-Transport-Bot-1.2\app.js:31:46)
at Client.emit (node:events:513:28)
at InteractionCreateAction.handle (E:\htcqq\Desktop\Federal-Transport-Bot-1.2\node_modules\discord.js\src\client\actions\InteractionCreate.js:97:12) at module.exports [as INTERACTION_CREATE] (E:\htcqq\Desktop\Federal-TranION_CREATE.js:4:36)
at WebSocketManager.handlePacket (E:\htcqq\Desktop\Federal-Transport-Bot-1.2\node_modules\discord.js\src\client\websocket\WebSocketManager.js:352:31)
ode_modules\discord.js\src\client\websocket\WebSocketShard.js:489:22)
at WebSocketShard.onMessage (E:\htcqq\Desktop\Federal-Transport-Bot-1.2\node_modules\discord.js\src\client\websocket\WebSocketShard.js:328:10) {
code: 'InvalidType'
}

Node.js v18.12.1
E:\htcqq\Desktop\Federal-Transport-Bot-1.2\node_modules\discord.js\src\managers\GuildMemberRoleManager.js:124
throw new DiscordjsTypeError(
^

TypeError [InvalidType]: Supplied roles is not a Role, Snowflake or Array or Collection of Roles or Snowflakes.
at GuildMemberRoleManager.add (E:\htcqq\Desktop\Federal-Transport-Bot-1.2\node_modules\discord.js\src\managers\GuildMemberRoleManager.js:124:15)
at Object.execute (E:\htcqq\Desktop\Federal-Transport-Bot-1.2\commands\slash\promote.js:26:16)
at Object.execute (E:\htcqq\Desktop\Federal-Transport-Bot-1.2\events\guild\interactioncreate.js:16:18)
at Client.<anonymous> (E:\htcqq\Desktop\Federal-Transport-Bot-1.2\app.js:31:46)
at Client.emit (node:events:513:28)
at InteractionCreateAction.handle (E:\htcqq\Desktop\Federal-Transport-Bot-1.2\node_modules\discord.js\src\client\actions\InteractionCreate.js:97:12) at module.exports [as INTERACTION_CREATE] (E:\htcqq\Desktop\Federal-TranION_CREATE.js:4:36)
at WebSocketManager.handlePacket (E:\htcqq\Desktop\Federal-Transport-Bot-1.2\node_modules\discord.js\src\client\websocket\WebSocketManager.js:352:31)
ode_modules\discord.js\src\client\websocket\WebSocketShard.js:489:22)
at WebSocketShard.onMessage (E:\htcqq\Desktop\Federal-Transport-Bot-1.2\node_modules\discord.js\src\client\websocket\WebSocketShard.js:328:10) {
code: 'InvalidType'
}

Node.js v18.12.1
but i confirm it's a role id yeah okay maybe there's something wrong with my json file i copied it from another json it works but how could it reply message to another channel while using interaction
MENIX
MENIX2y ago
Read into how to require and read the data from a json file - that isn’t really DiscordJS related. Pretty sure you cannot do const { something } = require(..json) Const something = require(…json) Would be correct. Then you gotta grab whatever you want from something like Something.CCroleId (CCroelId)
Unicorn.
Unicorn.OP2y ago
❤️the problem has solved
Want results from more Discord servers?
Add your server