mirror of
https://github.com/BluemediaGER/muse.git
synced 2024-11-23 01:05:30 +01:00
Improve commands registration
This commit is contained in:
parent
c20e3b1760
commit
827ff350ee
25
src/bot.ts
25
src/bot.ts
|
@ -109,10 +109,22 @@ export default class {
|
|||
|
||||
const spinner = ora('📡 connecting to Discord...').start();
|
||||
|
||||
this.client.once('ready', () => {
|
||||
this.client.once('ready', async () => {
|
||||
debug(generateDependencyReport());
|
||||
|
||||
spinner.succeed(`Ready! Invite the bot with https://discordapp.com/oauth2/authorize?client_id=${this.client.user?.id ?? ''}&scope=bot&permissions=2184236096`);
|
||||
spinner.text = '📡 Updating commands in all guilds...';
|
||||
|
||||
// Update commands
|
||||
const rest = new REST({version: '9'}).setToken(this.token);
|
||||
|
||||
this.client.guilds.cache.each(async guild => {
|
||||
await rest.put(
|
||||
Routes.applicationGuildCommands(this.client.user!.id, guild.id),
|
||||
{body: this.commandsByName.map(command => command.slashCommand ? command.slashCommand.toJSON() : null)},
|
||||
);
|
||||
});
|
||||
|
||||
spinner.succeed(`Ready! Invite the bot with https://discordapp.com/oauth2/authorize?client_id=${this.client.user?.id ?? ''}&scope=applications.commands%20bot&permissions=2184236096`);
|
||||
});
|
||||
|
||||
this.client.on('error', console.error);
|
||||
|
@ -121,15 +133,6 @@ export default class {
|
|||
this.client.on('guildCreate', handleGuildCreate);
|
||||
this.client.on('voiceStateUpdate', handleVoiceStateUpdate);
|
||||
|
||||
// Update commands
|
||||
await this.client.login(this.token);
|
||||
|
||||
const rest = new REST({version: '9'}).setToken(this.token);
|
||||
|
||||
await rest.put(
|
||||
Routes.applicationGuildCommands(this.client.user!.id, this.client.guilds.cache.first()!.id),
|
||||
// TODO: remove
|
||||
{body: this.commandsByName.map(command => command.slashCommand ? command.slashCommand.toJSON() : null)},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,14 +1,31 @@
|
|||
import {Guild, TextChannel, Message, MessageReaction, User} from 'discord.js';
|
||||
import {
|
||||
Guild,
|
||||
TextChannel,
|
||||
Message,
|
||||
MessageReaction,
|
||||
User,
|
||||
ApplicationCommandData,
|
||||
} from 'discord.js';
|
||||
import emoji from 'node-emoji';
|
||||
import pEvent from 'p-event';
|
||||
import {Settings} from '../models/index.js';
|
||||
import {chunk} from '../utils/arrays.js';
|
||||
import container from '../inversify.config.js';
|
||||
import Command from '../commands';
|
||||
import {TYPES} from '../types.js';
|
||||
|
||||
const DEFAULT_PREFIX = '!';
|
||||
|
||||
export default async (guild: Guild): Promise<void> => {
|
||||
await Settings.upsert({guildId: guild.id, prefix: DEFAULT_PREFIX});
|
||||
|
||||
// Setup slash commands
|
||||
const commands: ApplicationCommandData[] = container.getAll<Command>(TYPES.Command)
|
||||
.filter(command => command.slashCommand?.name)
|
||||
.map(command => command.slashCommand as ApplicationCommandData);
|
||||
|
||||
await guild.commands.set(commands);
|
||||
|
||||
const owner = await guild.client.users.fetch(guild.ownerId);
|
||||
|
||||
let firstStep = '👋 Hi!\n';
|
||||
|
|
|
@ -7,7 +7,7 @@ import Bot from './bot.js';
|
|||
import {sequelize} from './utils/db.js';
|
||||
import Config from './services/config.js';
|
||||
import FileCacheProvider from './services/file-cache.js';
|
||||
import metadata from '../package.json';
|
||||
import metadata from '../package.json' assert {type: "json"};
|
||||
|
||||
const bot = container.get<Bot>(TYPES.Bot);
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
"compilerOptions": {
|
||||
"lib": ["ES2019", "DOM"],
|
||||
"target": "es2018",
|
||||
"module": "ES2020",
|
||||
"module": "esnext",
|
||||
"moduleResolution": "node",
|
||||
"declaration": true,
|
||||
"outDir": "dist",
|
||||
|
|
Loading…
Reference in a new issue