Have bot DM you when you react to a specific message

hey, i am new to coding and was looking to create a discord bot that would DM you a a message when you react to a message, i was looking at other threads and they where out-dating or wouldnt help. can someone help me?

let msgId = [];

client.on("message", (message) => {
    if(message.content === "!command") {
        message.channel.send(
            new discord.MessageEmbed()
                .setAuthor("embed")
                .setDescription("react me with 😆")
        ).then(message => {
            msgId.push(message.id);
            message.react("😆");
        })
    }
})

client.on('messageReactionAdd', (reaction, user) => {
    if(user.id !== bot.user.id) {
        if(reaction.message.id === msgId[0]) {
            user.send("you reacted to my message!");
        }
    }
});

source : javascript - Trying to do discord.js on react emoji get dm - Stack Overflow

Basically, someone says !command and bot will send an embed and if someone reacts with :laughing: it would send a dm to user.

5 Likes

Hey, thanks for the response. I dont know if it works yet because i dont know how to input my message.
I want a message like this:

Hello,
This is an example

in between hello and this, i switched lines, when i switch lines it pops a ton of errors. is there some sort of symbol i have to show to switch for me?

Just what im looking for

ts-node index.ts
C:\Users\user\AppData\Roaming\npm\node_modules\ts-node\src\index.ts:692
return new TSError(diagnosticText, diagnosticCodes);
^
TSError: ⨯ Unable to compile TypeScript:
index.ts:23:7 - error TS7034: Variable ‘msgId’ implicitly has type ‘any’ in some locations where its type cannot be determined.

23 let msgId = ;
~~~~~
index.ts:28:19 - error TS2552: Cannot find name ‘discord’. Did you mean ‘DiscordJS’?

28 new discord.MessageEmbed()
~~~~~~~
index.ts:39:22 - error TS2304: Cannot find name ‘bot’.

39 if(user.id !== bot.user.id) {
~~~
index.ts:40:38 - error TS7005: Variable ‘msgId’ implicitly has an ‘any’ type.

40 if(reaction.message.id === msgId[0]) {
~~~~~

at createTSError (C:\Users\user\AppData\Roaming\npm\node_modules\ts-node\src\index.ts:692:12)
at reportTSError (C:\Users\user\AppData\Roaming\npm\node_modules\ts-node\src\index.ts:696:19)
at getOutput (C:\Users\user\AppData\Roaming\npm\node_modules\ts-node\src\index.ts:883:36)
at Object.compile (C:\Users\user\AppData\Roaming\npm\node_modules\ts-node\src\index.ts:1185:30)
at Module.m._compile (C:\Users\user\AppData\Roaming\npm\node_modules\ts-node\src\index.ts:1309:30)
at Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
at Object.require.extensions.<computed> [as .ts] (C:\Users\user\AppData\Roaming\npm\node_modules\ts-node\src\index.ts:1313:12)
at Module.load (node:internal/modules/cjs/loader:981:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:79:12) {

diagnosticText: “\x1B[96mindex.ts\x1B[0m:\x1B[93m23\x1B[0m:\x1B[93m7\x1B[0m - \x1B[91merror\x1B[0m\x1B[90m TS7034: \x1B[0mVariable ‘msgId’ implicitly has type ‘any’ in some locations where its type cannot be determined.\r\n” +
‘\r\n’ +
‘\x1B[7m23\x1B[0m let msgId = ;\r\n’ +
‘\x1B[7m \x1B[0m \x1B[91m ~~~~~\x1B[0m\r\n’ +
“\x1B[96mindex.ts\x1B[0m:\x1B[93m28\x1B[0m:\x1B[93m19\x1B[0m - \x1B[91merror\x1B[0m\x1B[90m TS2552: \x1B[0mCannot find name ‘discord’. Did you mean ‘DiscordJS’?\r\n” +
‘\r\n’ +
‘\x1B[7m28\x1B[0m new discord.MessageEmbed()\r\n’ +
‘\x1B[7m \x1B[0m \x1B[91m ~~~~~~~\x1B[0m\r\n’ +
“\x1B[96mindex.ts\x1B[0m:\x1B[93m39\x1B[0m:\x1B[93m22\x1B[0m - \x1B[91merror\x1B[0m\x1B[90m TS2304: \x1B[0mCannot find name ‘bot’.\r\n” +
‘\r\n’ +
‘\x1B[7m39\x1B[0m if(user.id !== bot.user.id) {\r\n’ +
‘\x1B[7m \x1B[0m \x1B[91m ~~~\x1B[0m\r\n’ +
“\x1B[96mindex.ts\x1B[0m:\x1B[93m40\x1B[0m:\x1B[93m38\x1B[0m - \x1B[91merror\x1B[0m\x1B[90m TS7005: \x1B[0mVariable ‘msgId’ implicitly has an ‘any’ type.\r\n” +
‘\r\n’ +
‘\x1B[7m40\x1B[0m if(reaction.message.id === msgId[0]) {\r\n’ +
‘\x1B[7m \x1B[0m \x1B[91m ~~~~~\x1B[0m\r\n’,
diagnosticCodes: [ 7034, 2552, 2304, 7005 ]
}

Are you using TypeScript?

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.