diff --git a/src/commands/listen.ts b/src/commands/listen.ts new file mode 100644 index 0000000..3f1c39d --- /dev/null +++ b/src/commands/listen.ts @@ -0,0 +1,26 @@ +import {ApplicationCommandType, ChatInputCommandInteraction } from "discord.js"; + +import Command, { ApplicationIntegrationType, InteractionContextTypes } from "../command"; + +export default class Listen extends Command implements Command { + // This command exists because Discord bots don't receive direct messages + // unless they explicitly open a DM channel with the user + name = "listen"; + description = "Makes the bot listen on your direct messages"; + type = ApplicationCommandType.ChatInput; + + options = []; + integration_types = [ + ApplicationIntegrationType.Guild_Install, + ApplicationIntegrationType.User_Install + ]; + contexts = [InteractionContextTypes.BotDM]; + + async execute(interaction: ChatInputCommandInteraction) { + await interaction.user.createDM(); + await interaction.reply({ + content: "I'm now listening to your direct messages", + ephemeral: true, + }); + } +} diff --git a/src/index.ts b/src/index.ts index a565a3f..eb7a9f7 100644 --- a/src/index.ts +++ b/src/index.ts @@ -11,6 +11,7 @@ const discord = new DiscordApi.Client({ intents: [ DiscordApi.GatewayIntentBits.Guilds, DiscordApi.GatewayIntentBits.GuildMessages, + DiscordApi.GatewayIntentBits.DirectMessages, DiscordApi.GatewayIntentBits.MessageContent, ] }); @@ -58,7 +59,9 @@ discord.on("ready", event => { discord.on("messageCreate", message => { if (message.author.bot) return; - if (!message.mentions.has(message.client.user, { ignoreEveryone: true })) return; + if (!message.channel.isDMBased()) { + if (!message.mentions.has(message.client.user, { ignoreEveryone: true })) return; + } return queueRequest(message); });