import { CommandContext, CommandOptionType, SlashCommand, SlashCreator } from 'slash-create' import { PrismaClient } from '@prisma/client' export default class MessagesCommand extends SlashCommand { constructor(creator: SlashCreator) { super(creator, { name: 'messages', description: 'show message count, either for yourself, or someone else', options: [ { name: 'user', description: 'person to show messages for (blank shows your own)', required: false, type: CommandOptionType.USER } ] }) } async run(ctx: CommandContext) { const prisma = new PrismaClient() if (ctx.options.user == null) { const u = await prisma.user.findFirst({ where: { id: ctx.member?.id, guild: { id: ctx.guildID } } }) if (!u) return `you have no messages!` return `you have ${u.messages} message(s)` } else { const uid = ctx.options.user const u = await prisma.user.findFirst({ where: { id: uid, guild: { id: ctx.guildID } } }) if (!u) return `this user has no messages!` const uu = await this.client.users.fetch(u.id) return `${uu.username}#${uu.discriminator} has ${u.messages} message(s)` } } }