A fun game to steal a role back and forth between your friends with a specified delay! Just use the prefix command followed by the user you want to steal from: "!stealrole @user". Don't forget to add the role on line 5 in the code. Note that you cannot steal roles that are higher than your bot's role! I also made a slash command version (https://autocode.com/snippet/MeltedButter77/cachsnpt_FWXxhpGTDsfPDkwACHWP671fuRHyV9BNABe6/)
const lib = require('lib')({token: process.env.STDLIB_SECRET_TOKEN});
let authorString = context.params.event.author.id;
let stealRole = [`Role ID here`]; //The id of the role that gets passed around
if (context.params.event.content.startsWith('!stealrole')) {
let userString = context.params.event.content.split(' ')[1];
//get all roles on the mentioned user
let hasStealRole = context.params.event.mentions[0].member.roles.find(
(roleId) => {
return stealRole.includes(roleId); //check if user's roles includes stealRole
}
);
let timeLimit = await lib.utils.kv['@0.1.16'].get({
key: `rate_limit_example`,
});
//if the cooldown is active send this msg
if (timeLimit) {
return lib.discord.channels['@0.1.1'].messages.create({
channel_id: `${context.params.event.channel_id}`,
content: `Sorry <@${authorString}>, you gotta wait!`,
});
}
//if the mentioned user has the stealRole
if (hasStealRole) {
//take stealRole from userString
let result = await lib.discord.guilds['@0.1.0'].members.roles.destroy({
role_id: `${stealRole}`,
user_id: `${userString}`,
guild_id: `${context.params.event.guild_id}`,
});
//give stealRole to authorString
await lib.discord.guilds['@0.1.0'].members.roles.update({
role_id: `${stealRole}`,
user_id: `${authorString}`,
guild_id: `${context.params.event.guild_id}`,
});
//create msg saying it worked
await lib.discord.channels['@0.2.0'].messages.create({
channel_id: `${context.params.event.channel_id}`,
content: `<@${authorString}> stole the role <@&${stealRole}> from ${userString}!`,
});
//the cooldown is ttl in seconds
await lib.utils.kv['@0.1.16'].set({
key: `rate_limit_example`,
value: `true`,
ttl: 100, // The number of seconds to rate limit a person for.
});
} else { //if hasStealRole didnt get triggered
await lib.discord.channels['@0.2.0'].messages.create({
channel_id: `${context.params.event.channel_id}`,
content: `They do not have the role!`,
});
}
}
//.MeltedButter#9266