I am working on creating a Discord bot that creates a role based on arguments entered in the command and then assigns that role to mentioned users in the same message. The role gets created just fine, but I'm having issues then assigning the role to even the author of the message (me) let alone multiple mentions within the message. I've deduced that the role cannot be found, so therefore it cannot be assigned to the users, but I don't know why it can't be found.
I'm using
message.guild.roles.create({
data: {
name: roleName,
color: 'BLUE'
}
})
.catch(console.error);
(where roleName
is defined as the first argument of the command) to create the role, and then
let role = message.guild.roles.cache.find(role => role.name === roleName);
to search for the role by name (which I attempt to print to the console, but it is returned as undefined
).
Is it possible to both create and give a role within one command?