cmd.user.edit.roles.add

Adds one or more roles to a guild member. Roles are assigned one at a time in the order provided.

JavaScript
const { cmd } = require("syntx.js");

await cmd.user.edit.roles.add({ user, roles }, message);

Parameters

ParameterTypeRequiredDescription
userstringYesThe ID of the member to assign roles to.
rolesstring[]YesArray of role IDs to add. Must contain at least one entry.
messagediscord.js MessageYesA guild message or interaction, used to access the guild.

Returns

This function does not return a value.

Example

JavaScript
client.command({
  name: "addrole",
  content: async (message) => {
    const id = cmd.message.mentioned(message, 1);
    if (!id) return message.reply("Please mention a user.");

    await cmd.user.edit.roles.add(
      {
        user: id,
        roles: ["ROLE_ID_1", "ROLE_ID_2"],
      },
      message
    );

    message.reply("Roles added.");
  },
});

Warning

The bot must have the Manage Roles permission and its highest role must be above each role it is trying to assign. If any role ID is not found in the guild, a SyntxError is thrown immediately and remaining roles in the array will not be processed.