Find a role by name then update it

How do I find a role in a guild by it's name. Then update it's info?
guild.roles.cache.find(role => role.name === 'Yara').then((role) => {
role.edit({ name: '🤖Yara', colour: '#ff5757'});
});
guild.roles.cache.find(role => role.name === 'Yara').then((role) => {
role.edit({ name: '🤖Yara', colour: '#ff5757'});
});
Does this code work. Note that this is in the guildCreate event
16 Replies
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
PAdventures
PAdventuresOP3y ago
oh yeah oops thanks
Syjalo
Syjalo3y ago
<Collection>.find() doesn't return a Promise
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
PAdventures
PAdventuresOP3y ago
TypeError: guild.roles.cache.find(...).then is not a function
at Object.execute (E:\Yara Bot\Events\Guild\guildCreate.js:16:70)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
TypeError: guild.roles.cache.find(...).then is not a function
at Object.execute (E:\Yara Bot\Events\Guild\guildCreate.js:16:70)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
guild.roles.me.edit({ name: '🤖Yara', color: '#ff5757', position: 4 });
guild.roles.me.edit({ name: '🤖Yara', color: '#ff5757', position: 4 });
would that work instead?
Syjalo
Syjalo3y ago
.find() returns a Role or undefined, not a Promise You can't do .then()
PAdventures
PAdventuresOP3y ago
would this work if I am trying to edit the bot's role?
Syjalo
Syjalo3y ago
No roles.me is not a think
PAdventures
PAdventuresOP3y ago
guild.roles.client.edit?
Syjalo
Syjalo3y ago
<Guild>.roles.botRoleFor(client.user).edit()
PAdventures
PAdventuresOP3y ago
k would guild.client.user work? or does it have to be client.user?
Syjalo
Syjalo3y ago
Yes, it would
PAdventures
PAdventuresOP3y ago
k
E:\Yara Bot\node_modules\@discordjs\rest\dist\index.js:743
throw new DiscordAPIError(data, "code" in data ? data.code : data.error, status, method, url, requestData);
^

DiscordAPIError[50013]: Missing Permissions
at SequentialHandler.runRequest (E:\Yara Bot\node_modules\@discordjs\rest\dist\index.js:743:15)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async SequentialHandler.queueRequest (E:\Yara Bot\node_modules\@discordjs\rest\dist\index.js:549:14)
at async REST.request (E:\Yara Bot\node_modules\@discordjs\rest\dist\index.js:988:22)
at async RoleManager.edit (E:\Yara Bot\node_modules\discord.js\src\managers\RoleManager.js:209:15) {
requestBody: {
files: undefined,
json: {
name: '🤖Yara',
color: 16734039,
hoist: undefined,
permissions: undefined,
mentionable: undefined,
icon: undefined,
unicode_emoji: undefined
}
},
rawError: { message: 'Missing Permissions', code: 50013 },
code: 50013,
status: 403,
method: 'PATCH',
url: 'https://discord.com/api/v10/guilds/997223618700390420/roles/1049031351598325925'
}
E:\Yara Bot\node_modules\@discordjs\rest\dist\index.js:743
throw new DiscordAPIError(data, "code" in data ? data.code : data.error, status, method, url, requestData);
^

DiscordAPIError[50013]: Missing Permissions
at SequentialHandler.runRequest (E:\Yara Bot\node_modules\@discordjs\rest\dist\index.js:743:15)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async SequentialHandler.queueRequest (E:\Yara Bot\node_modules\@discordjs\rest\dist\index.js:549:14)
at async REST.request (E:\Yara Bot\node_modules\@discordjs\rest\dist\index.js:988:22)
at async RoleManager.edit (E:\Yara Bot\node_modules\discord.js\src\managers\RoleManager.js:209:15) {
requestBody: {
files: undefined,
json: {
name: '🤖Yara',
color: 16734039,
hoist: undefined,
permissions: undefined,
mentionable: undefined,
icon: undefined,
unicode_emoji: undefined
}
},
rawError: { message: 'Missing Permissions', code: 50013 },
code: 50013,
status: 403,
method: 'PATCH',
url: 'https://discord.com/api/v10/guilds/997223618700390420/roles/1049031351598325925'
}
I (Bot )has ManageRoles permission though this is how i assign intents / patials
const client = new Client({
intents: [Object.keys(GatewayIntentBits)],
partials: [Object.keys(Partials)],
});
const client = new Client({
intents: [Object.keys(GatewayIntentBits)],
partials: [Object.keys(Partials)],
});
d.js docs
d.js docs3y ago
We highly recommend only specifying the intents you actually need. • Note, that 98303, 32767 or whatever other magic number you read that represents "all intents", gets outdated as soon as new intents are introduced. • The number will always represent the same set of intents, and will not include new ones. There is no magic "all intents" bit.
PAdventures
PAdventuresOP3y ago
same error occurs every time is this because the bot can't update it's own role? ^^^
CanineData
CanineData3y ago
If that role is it's highest role then it can't edit it

Did you find this page helpful?