-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathgiverole.ts
57 lines (49 loc) · 1.35 KB
/
giverole.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import { createCommand } from '$discord'
import type { Role, User, InteractionReplyOptions } from 'discord.js'
async function handler(interaction): Promise<InteractionReplyOptions | string> {
const { member: caller, guild } = interaction
const { role, user } = interaction.options.data.reduce(
(acc, current, index, source) => {
return {
...acc,
[current.name]: current[current.name],
}
},
{}
) as { role: Role; user: User }
if (user.bot) {
return 'This command does not support adding roles to bots.'
}
if (caller.id === user.id) {
return `This command does not support adding roles to yourself.`
}
if (guild.members.cache.get(user.id).roles.add(role)) {
return `Successfully added role \`${role.name}\` to ${user.username}#${user.discriminator}.`
}
return '🤢 something went wrong'
}
const command = createCommand({
name: 'giverole',
description: 'Gives role to user',
enabledByDefault: false, // todo: restrict who can execute
options: [
{
name: 'role',
description: 'Role to give',
type: 8,
required: true,
},
{
name: 'user',
description: 'User to receive role',
type: 6,
required: true,
},
],
handler,
})
export default command
if (import.meta.vitest) {
const { test } = import.meta.vitest
test.todo('/giverole')
}