Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { GuildMember, Message, Client, Intents } from "discord.js";
import { Client, Events, GatewayIntentBits, GuildMember, Message } from "discord.js";
import * as dotenv from "dotenv";
import { CronJob } from "cron";
import SendWelcomeMessageUseCase from "./application/usecases/sendWelcomeMessageUseCase";
Expand All @@ -24,7 +24,12 @@ dotenv.config();
const { DISCORD_TOKEN } = process.env;

const client = new Client({
intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MEMBERS, Intents.FLAGS.GUILD_MESSAGES],
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMembers,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent,
],
});

const messageRepository: MessageRepository = new FileMessageRepository();
Expand Down Expand Up @@ -89,7 +94,7 @@ const setupCron = () => {
);
};

client.once("ready", () => {
client.once(Events.ClientReady, () => {
loggerService.log("Ready!");
setupCron();
});
Expand All @@ -105,7 +110,7 @@ client.on("guildMemberAdd", (member: GuildMember) =>
}).execute(member)
);

client.on("messageCreate", (messages: Message) => {
client.on(Events.MessageCreate, (messages: Message) => {
const COMMAND_PREFIX = "!";

if (!messages.content.startsWith(COMMAND_PREFIX)) return;
Expand Down
7 changes: 4 additions & 3 deletions infrastructure/service/discordChatService.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Client } from "discord.js";
import { Client, TextBasedChannel } from "discord.js";
import ChatService from "../../domain/service/chatService";

export default class DiscordChatService implements ChatService {
Expand All @@ -11,10 +11,11 @@ export default class DiscordChatService implements ChatService {
throw new Error(`Channel with id ${channelId} not found!`);
}

if (!channel.isText()) {
if (!channel.isTextBased() || !("send" in channel)) {
throw new Error(`Channel with id ${channelId} is not a text channel!`);
}

channel.send(message);
const textChannel = channel as TextBasedChannel & { send: (content: string) => Promise<unknown> };
await textChannel.send(message);
}
}
Loading