♻️ Migrate guildCreate to Prisma

This commit is contained in:
Axel Olausson Holtenäs 2022-10-19 09:54:05 +02:00
parent a568daaadd
commit 10283f911b

View file

@ -1,7 +1,8 @@
import { Guild } from "discord.js"; import { Guild } from "discord.js";
import fetchGuild from "../../../helpers/guildData";
import updatePresence from "../../../helpers/updatePresence"; import updatePresence from "../../../helpers/updatePresence";
import { IEventOptions } from "../../../interfaces/EventOptions"; import { IEventOptions } from "../../../interfaces/EventOptions";
import logger from "../../../middlewares/logger";
import prisma from "../../../prisma";
export const options: IEventOptions = { export const options: IEventOptions = {
type: "on", type: "on",
@ -10,6 +11,40 @@ export const options: IEventOptions = {
export const execute = async (guild: Guild) => { export const execute = async (guild: Guild) => {
const { client } = guild; const { client } = guild;
await fetchGuild(guild);
await updatePresence(client); await updatePresence(client);
// Create guildMember object
const createGuildMember = await prisma.guildMember.upsert({
where: {
userId_guildId: {
userId: guild.ownerId,
guildId: guild.id,
},
},
update: {},
create: {
user: {
connectOrCreate: {
create: {
id: guild.ownerId,
},
where: {
id: guild.ownerId,
},
},
},
guild: {
connectOrCreate: {
create: {
id: guild.id,
},
where: {
id: guild.id,
},
},
},
},
});
logger.silly(createGuildMember);
}; };