Time out a member by using !timeout @someone. This is a permission restricted prefix command. Only moderators can use this command.
const lib = require('lib')({token: process.env.STDLIB_SECRET_TOKEN});
let canUseAdminCommands = false;
let guildInfo = await lib.discord.guilds['@0.2.1'].retrieve({
guild_id: `${context.params.event.guild_id}`,
});
let roles = await lib.discord.guilds['@0.2.1'].roles.list({
guild_id: `${context.params.event.guild_id}`,
});
let userRoles = roles.filter((role) =>
context.params.event.member.roles.includes(role.id)
);
for (let i = 0; i < userRoles.length; i++) {
let _role = userRoles[i];
if (
_role.permission_names.includes('MODERATE_MEMBERS') ||
_role.permission_names.includes('ADMINISTRATOR')
) {
canUseAdminCommands = true;
break;
}
}
if (guildInfo.owner_id === context.params.event.author.id) {
canUseAdminCommands = true;
}
if (canUseAdminCommands) {
try {
await lib.discord.guilds['@0.2.1'].members.timeout.update({
user_id: `${context.params.event.mentions[0].id}`,
guild_id: `${context.params.event.guild_id}`,
communication_disabled_until_seconds: 86400, //timeout will set to 1 day
reason: `Using bad language.`, //You may change this
});
await lib.discord.channels['@0.3.0'].messages.create({
channel_id: `${context.params.event.channel_id}`,
content: `1 Day time out set to <@!${context.params.event.mentions[0].id}>`,
});
} catch (e) {
await lib.discord.channels['@0.3.0'].messages.create({
channel_id: `${context.params.event.channel_id}`,
content: `I can't timeout that user!`
});
}
} else {
await lib.discord.channels['@0.1.2'].messages.create({
channel_id: `${context.params.event.channel_id}`,
content: `You are not allowed to use this command!`,
});
}