import {Client, Guild} from 'discord.js'; import container from '../inversify.config.js'; import Command from '../commands'; import {TYPES} from '../types.js'; import Config from '../services/config.js'; import {prisma} from '../utils/db.js'; import {REST} from '@discordjs/rest'; import {Setting} from '@prisma/client'; import registerCommandsOnGuild from '../utils/register-commands-on-guild.js'; export async function createGuildSettings(guild: Guild): Promise { return prisma.setting.upsert({ where: { guildId: guild.id, }, create: { guildId: guild.id, }, update: {}, }); } export default async (guild: Guild): Promise => { await createGuildSettings(guild); const config = container.get(TYPES.Config); // Setup slash commands if (!config.REGISTER_COMMANDS_ON_BOT) { const client = container.get(TYPES.Client); const rest = new REST({version: '10'}).setToken(config.DISCORD_TOKEN); await registerCommandsOnGuild({ rest, applicationId: client.user!.id, guildId: guild.id, commands: container.getAll(TYPES.Command).map(command => command.slashCommand), }); } const owner = await guild.fetchOwner(); await owner.send('👋 Hi! Someone (probably you) just invited me to a server you own. By default, I\'m usable by all guild member in all guild channels. To change this, check out the wiki page on permissions: https://github.com/codetheweb/muse/wiki/Configuring-Bot-Permissions.'); };