#How do I get the referenced user id from a referenced message?

12 messages · Page 1 of 1 (latest)

spiral rock
#
let prevMessages = await message.channel.messages.fetch({ limit: 15 });
            prevMessages.reverse();
            await message.channel.sendTyping()
  
            prevMessages.forEach((msg) => {
                if (msg.author.id === message.author.id) {
                    conversationLog.push({
                        "role": "user",
                        "content": msg.content
                    });
                } else if (msg.author.bot && /* is a reference to a message sent by the msg.author*/) {
                    conversationLog.push({
                        "role": "assistant",
                        "content": msg.content
                    });
                }
            });``` Heres my code
celest harnessBOT
#

• What's your exact discord.js npm list discord.js and node node -v version?
• Post the full error stack trace, not just the top part!
• Show your code!
• Explain what exactly your issue is.
• Not a discord.js issue? Check out #useful-servers.

craggy badge
spiral rock
#

I use the openai api, and want to provide a bit more context to the answers. Because of that I want add the assistant role to the conversation log so that the bot doesnt repeat answers. What im trying to find out is how to get the referenced user of a message (like in the picture) to add the response to the conversation log. So that it only adds the replies of the conversation with the certain user to the log. (sorry for bad english) i hope this makes sense

craggy badge
spiral rock
craggy badge
#

Alright, let me check the documentation

craggy badge
meager quailBOT
craggy badge
#

Note that the function is an async function and it could throw an error if there's no message reference

spiral rock
#

alr ima try that

spiral rock
# craggy badge Note that the function is an `async` function and it could throw an error if the...

tried it and works ty ❤️ . One other question tho, do you know why I can't get the msg.author.id in this rewritten code:

let prevMessages = await message.channel.messages.fetch({ limit: 15 });
for (const msg of prevMessages) {
                if (isUser) {
                    if (msg.author.id === message.author.id) {
                          ...  }

I just get an error that says that it doesnt have an id TypeError: Cannot read properties of undefined (reading 'id')