This is a simple snippet for randomly assigning roles. It is meant to be a fun command:) You can create multiple funny roles for the bot to assign and run the slash command. It's that ez:) The same concept can be applied on prefix commands and button interactions. See the following thread to learn how to convert slash command to prefix command and vice versa: https://autocode.com/notedwin-but-bot/threads/guide-2-converting-prefix-command-to-slash-command-or-vice-versa-92bedd79/
// authenticates you with the API standard library
// type `await lib.` to display API autocomplete
const lib = require('lib')({token: process.env.STDLIB_SECRET_TOKEN});
const {guild_id, channel_id, member, token} = context.params.event;
await lib.discord.commands['@0.1.1'].create({
guild_id: `${guild_id}`,
name: `random-roles`,
description: `Randomly assigns a role to you. Used as a fun command:)`,
});
await lib.discord.interactions['@1.0.1'].responses.create({
token: `${token}`,
response_type: 'DEFERRED_CHANNEL_MESSAGE_WITH_SOURCE',
});
let roles = await lib.discord.guilds['@0.2.4'].roles.list({
guild_id: `${guild_id}`,
});
let random_role = roles[Math.floor(Math.random() * roles.length)];
await lib.discord.guilds['@0.2.4'].members.roles.update({
role_id: `${random_role.id}`,
user_id: `${member.user.id}`,
guild_id: `${guild_id}`,
});
await lib.discord.interactions['@1.0.1'].responses.update({
token: `${token}`,
content: `<@!${member.user.id}> ran the random roles command and got <@&${random_role.id}>!`,
});