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 User2y ago
Message Not Public
Sign In & Join Server To View
PAdventures
PAdventures2y ago
oh yeah oops thanks
Syjalo
Syjalo2y ago
<Collection>.find() doesn't return a Promise
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
PAdventures
PAdventures2y 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
Syjalo2y ago
.find() returns a Role or undefined, not a Promise You can't do .then()
PAdventures
PAdventures2y ago
would this work if I am trying to edit the bot's role?
Syjalo
Syjalo2y ago
No roles.me is not a think
PAdventures
PAdventures2y ago
guild.roles.client.edit?
Syjalo
Syjalo2y ago
<Guild>.roles.botRoleFor(client.user).edit()
PAdventures
PAdventures2y ago
k would guild.client.user work? or does it have to be client.user?
Syjalo
Syjalo2y ago
Yes, it would
PAdventures
PAdventures2y 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 docs2y 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
PAdventures2y ago
same error occurs every time is this because the bot can't update it's own role? ^^^
CanineData
CanineData2y ago
If that role is it's highest role then it can't edit it