harmony/test/class.ts

71 lines
1.5 KiB
TypeScript
Raw Normal View History

import {
CommandClient,
event,
Intents,
command,
CommandContext,
2020-12-08 06:43:06 +00:00
Extension,
CommandBuilder
2021-04-04 05:52:47 +00:00
} from '../mod.ts'
import { TOKEN } from './config.ts'
class MyClient extends CommandClient {
constructor() {
super({
2020-12-08 07:05:34 +00:00
prefix: ['!', '!!'],
caseSensitive: false
})
}
@event()
ready(): void {
console.log(`Logged in as ${this.user?.tag}!`)
}
2020-12-08 06:43:06 +00:00
@command({ aliases: 'pong' })
Ping(ctx: CommandContext): void {
ctx.message.reply('Pong!')
}
}
class VCExtension extends Extension {
2020-12-08 06:43:06 +00:00
name = 'VC'
subPrefix = 'vc'
@command()
async join(ctx: CommandContext): Promise<void> {
const userVS = await ctx.guild?.voiceStates.get(ctx.author.id)
if (userVS === undefined) {
ctx.message.reply("You're not in VC.")
return
}
await userVS.channel?.join()
ctx.message.reply(`Joined VC channel - ${userVS.channel?.name}!`)
}
@command()
async leave(ctx: CommandContext): Promise<void> {
const userVS = await ctx.guild?.voiceStates.get(
(ctx.client.user?.id as unknown) as string
)
if (userVS === undefined) {
ctx.message.reply("I'm not in VC.")
return
}
userVS.channel?.leave()
ctx.message.reply(`Left VC channel - ${userVS.channel?.name}!`)
}
}
const client = new MyClient()
client.extensions.load(VCExtension)
2020-12-08 06:43:06 +00:00
client.commands.add(
new CommandBuilder()
.setName('join')
.onExecute((ctx) => ctx.message.reply('haha'))
)
client.connect(TOKEN, Intents.All)