#Unknown User

1 messages · Page 1 of 1 (latest)

toxic vigil
#

But my code is:

let member = message.mentions.members.first() || await message.guild.members.fetch({ user: args[0], force: true })

@terse urchin

#

And I already have a line that checks if member.user is an object.

terse urchin
#

then you need to elaborate what you mean by known user, I thought that was what you meant

toxic vigil
#

Well...

A friend of mine used the command wrong, and instead of the userID first, he did the messageID first.

toxic vigil
#

Do you get what I mean? @terse urchin

#

Unknown User

waxen hornet
#

Can you show the full error + stack

toxic vigil
#
throw new DiscordAPIError(data, res.status, request);
            ^

DiscordAPIError: Unknown User
    at RequestHandler.execute (/home/runner/StormMC-Discord-Bot/node_modules/discord.js/src/rest/RequestHandler.js:350:13)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async RequestHandler.push (/home/runner/StormMC-Discord-Bot/node_modules/discord.js/src/rest/RequestHandler.js:51:14)
    at async GuildMemberManager._fetchSingle (/home/runner/StormMC-Discord-Bot/node_modules/discord.js/src/managers/GuildMemberManager.js:407:18) {
  method: 'get',
  path: '/guilds/948561490552684544/members/950860734668103711',
  code: 10013,
  httpStatus: 404,
  requestData: { json: undefined, files: [] }
}
waxen hornet
#

Pretty much just means args[0] isnt the ID of a GuildMember

#

404 not found

toxic vigil
#

I know, it was a messageID. But how can I make it so it will then return an error if it isn't a UserID?

waxen hornet
#

It is returning an error

#

Catch it

toxic vigil
#

Where 🤣

#
let args = message.content.split(" ")
  args.shift()
  let member = message.mentions.members.first() || await message.guild.members.fetch({ user: args[0], force: true })
  args.shift()
  let SuggestionID = args.join(" ")

  if(!member.user) return message.reply("Je moet wel even zeggen wie de suggestie heeft ingevoerd, zodat ik diegene op de hoogte kan brengen!")
#

Or... Do I have to catch .fetch()?

waxen hornet
#

yeah you can chain a catch onto it, which will probably result in it returning undefined

#

So you'd want to optional chain member?.user

#

Or yoiu can try/catch the whole block

toxic vigil
#

.fetch().catch() is the same as !member.user?

#

I guess so...

waxen hornet
#

no, it isnt

toxic vigil
#

Explain...

waxen hornet
#

It will catch the error from the Promise rejecting and allow you to handle it

#

Since you're using await, awaiting it will resolve to the value of what the .catch function returns (not a member)

#

So you still need to check it

toxic vigil
#

But that is what it should do...

#

If it is not a member, it should return an error.

#

.catch() does this, I just tested it out.

#

Or am I wrong into that?

waxen hornet
#

"return" to where though? Im not sure what you mean

toxic vigil
waxen hornet
#

It will log one to the console if thats what you tell it to do

#

But using a chained .catch() doesnt stop the execution of the rest of the function

toxic vigil
#

Ahhhh

#

I noticed that 🤣