Untitled
unknown
javascript
a year ago
2.4 kB
9
Indexable
const { Client, Intents } = require('discord.js');
const axios = require('axios');
const client = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES, Intents.FLAGS.GUILD_MEMBERS] });
const GUILD_ID = 'YOUR_GUILD_ID';
const ROLE_PARTNER = 'ROLE_PARTNER_ID';
const ROLE_AFFILIATE = 'ROLE_AFFILIATE_ID';
const ROLE_CREATOR = 'ROLE_CREATOR_ID';
client.once('ready', () => {
console.log(`Logged in as ${client.user.tag}`);
});
client.on('interactionCreate', async interaction => {
if (!interaction.isCommand()) return;
const { commandName } = interaction;
if (commandName === 'assign_role') {
const { broadcaster_type, discord_user_id } = interaction.options.data[0].value;
try {
const guild = client.guilds.cache.get(GUILD_ID);
if (!guild) {
await interaction.reply({ content: 'Guild not found', ephemeral: true });
return;
}
const member = await guild.members.fetch(discord_user_id);
if (!member) {
await interaction.reply({ content: 'Member not found', ephemeral: true });
return;
}
let roleToAssign;
if (broadcaster_type === 'partner') {
roleToAssign = guild.roles.cache.get(ROLE_PARTNER);
} else if (broadcaster_type === 'affiliate') {
roleToAssign = guild.roles.cache.get(ROLE_AFFILIATE);
} else {
roleToAssign = guild.roles.cache.get(ROLE_CREATOR);
}
if (!roleToAssign) {
await interaction.reply({ content: 'Role not found', ephemeral: true });
return;
}
if (roleToAssign.position >= client.user.roles.highest.position) {
await interaction.reply({ content: 'Bot cannot assign this role', ephemeral: true });
return;
}
await member.roles.add(roleToAssign);
await interaction.reply({ content: 'Role assigned successfully', ephemeral: true });
} catch (error) {
console.error(error);
await interaction.reply({ content: `Error assigning role: ${error.message}`, ephemeral: true });
}
}
});
client.login('YOUR_DISCORD_BOT_TOKEN');
Editor is loading...
Leave a Comment