Skip to content

Commit

Permalink
Fixes #16. Бот теперь отвечает и в личке Discord
Browse files Browse the repository at this point in the history
  • Loading branch information
erickskrauch committed Apr 12, 2024
1 parent 8f4b51f commit 5957cdf
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/discord.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Client as DiscordClient, Events, GatewayIntentBits } from 'discord.js';
import { ChannelType, Client as DiscordClient, Events, GatewayIntentBits, Partials } from 'discord.js';
import { escapeMarkdown } from '@discordjs/formatters';
import { BotLauncher, MessageHandler, ShutdownFunction } from './Engine';
import UnconfiguredException from './UnconfiguredException';
Expand All @@ -19,6 +19,10 @@ export function launch(token: string, handler: MessageHandler): Promise<Shutdown
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent,
GatewayIntentBits.DirectMessages,
],
partials: [
Partials.Channel,
],
});
discord.login(token).then(() => {
Expand Down Expand Up @@ -46,7 +50,11 @@ export function launch(token: string, handler: MessageHandler): Promise<Shutdown
return;
}

message.channel.send(escapeMarkdown(response)).catch(console.error);
if (message.channel.type === ChannelType.DM) {
message.author.send(escapeMarkdown(response)).catch(console.error);
} else {
message.channel.send(escapeMarkdown(response)).catch(console.error);
}
});

discord.on(Events.Error, console.error);
Expand Down

0 comments on commit 5957cdf

Please sign in to comment.