Here’s the situation:
In my server I have a bot (not mine) that replies to specific user actions with a message containing an embed that has the word “Done!” in the description. I want to set it up so that once this bot sends the “Done!” message the user it replied to receives a role.
Today being the first day I’ve ever used javascript means I’m not surprised I’ve encountered an error, however I simply could not figure out how to fix it. I tried working around the error by attempting to achieve my intended result by different methods, but I cannot find an actual alternative so I’ve ended up back at the error.
The code that I’m experiencing the error with is this:
client.on('messageCreate', (message) => { let role = message.guild.roles.cache.find(r => r.id === "1001628984829816952"); let member = message.mentions.repliedUser(); let done = "done!" if (done(w => message.embeds.description.toLowerCase().includes(w))) { member.roles.add(role); } });
and the error I’m receiving is this:
let member = message.mentions.repliedUser(); ^ TypeError: message.mentions.repliedUser is not a function
I’m a bit confused as I was sure .repliedUser
is valid, although this may be my absolute inexperience with javascript shining through.
On a side note, I believe I have the necessary intents enabled:
import { Client, GatewayIntentBits } from 'discord.js'; import dotenv from 'dotenv' dotenv.config() const client = new Client({ intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages, GatewayIntentBits.MessageContent] });
so those shouldn’t be a problem.
What I’ve tried by means of my own intuitive bumbling is replacing message.mentions.repliedUser()
with message.mentions.repliedUser.get()
since I’ve seen .get
used at the end a bit like that and it sounds about right (I’m laughing at my own explanation here, please bear with me…), however I receive a different error with that in place:
let member = message.mentions.repliedUser.get(); ^ TypeError: Cannot read properties of null (reading 'get')
I’m not surprised by this result, though, (even if I don’t fully understand what it’s trying to tell me…) since .repliedUser
isn’t recognised anyways.
I’m not really sure where to go from here, especially since there seems to be no mention of .repliedUser
anywhere on the internet except for the discord.js docs, and also because much of the general help for discord.js is still aimed at v13, whereas I’m running v14, and the two are not compatible.
Any and all help is much appreciated, and I’m sorry if this question is stupid and the answer to it is incredibly rudimentary, which I’m guessing it is. I also hope that my code is readable; it seems to mostly work, except for the error, but it is also mostly patchwork so it could just be some nonsense that’s pretending to work.
(At least this has convinced me to get into javascript properly, even if only for my own peace of mind.)
Advertisement
Answer
Looking at the documentation, message.mentions.repliedUser is of type ?User
. You are expecting it to be of type (...) => ?User
, which it isn’t.
Simple fix, just replace .repliecUser()
with .repliedUser
.