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
#How do I get the referenced user id from a referenced message?
12 messages · Page 1 of 1 (latest)
• 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.
I'm unsure what you want to know - you can get the user id of a message by using <Message>.author.id as you also did before in your code.
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
Oh, you mean the message it replied to?
I want the user id of the original message that has been replied to, so that i can check if it isn't an other user
Alright, let me check the documentation
You want to fetch the referenced Message with <Message>.fetchReference() which returns a Message object if there's a reference. Of that object you can check the .author.id to get the author id.
Message#fetchReference()
Fetches the Message this crosspost/reply/pin-add references, if available to the client
Note that the function is an async function and it could throw an error if there's no message reference
alr ima try that
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')