0

So Im making a ticket command and when you say .new it will open a channel and store message.author so it can dm you a transcript later on when you close it. When I log Console.log(message.author) and the stored person in the db, the message.author has User before the brackets and in the db it does not. Also the db has more lines while message.author has less:

MEMBER:  {
  id: '708457617013342249',
  system: false,
  locale: null,
  flags: 128,
  username: 'chuli',
  bot: false,
  discriminator: '0001',
  avatar: 'a_483669232f603ee04c099c0449e8dc6a',
  lastMessageChannelID: '829491485866065971',
  createdTimestamp: 1588979858402,
  defaultAvatarURL: 'https://cdn.discordapp.com/embed/avatars/1.png',
  tag: 'chuli#0001',
  avatarURL: 'https://cdn.discordapp.com/avatars/708457617013342249/a_483669232f603ee04c099c0449e8dc6a.webp',
  displayAvatarURL: 'https://cdn.discordapp.com/avatars/708457617013342249/a_483669232f603ee04c099c0449e8dc6a.webp'
}
MESSAGE.AUTHOR User {
  id: '708457617013342249',
  system: false,
  locale: null,
  flags: UserFlags { bitfield: 128 },
  username: 'chuli',
  bot: false,
  discriminator: '0001',
  avatar: 'a_483669232f603ee04c099c0449e8dc6a',
  lastMessageID: '842016982039134249',
  lastMessageChannelID: '841958995890667530'
}

So I get an error when trying to send to the stored db user:

 member.send(pembed).catch()
       ^                                                

TypeError: member.send is not a function

Ive been breaking my head over this so I hope someone has the answer to this out there!

Chuli
  • 3
  • 1
  • What kind of database are you using? Are you trying to store the whole user/member objects in your database? You should only store their IDs and then recover the cached member/user through `client.members.fetch(id)` or `client.users.fetch(id)` – Pedro Fracassi May 12 '21 at 12:55

2 Answers2

0

The reason they have different amount of lines is because they are two different things. message.author is a User, but what's stored in the db is a GuildMember. What's the difference?

The reason that message.author has User in front of it is that it's a class. What's in the db was originally a class, and would've been logged with GuildMember in front of it, however you unfortunately cannot keep classes in quick.db. Nor should you want to, as it would take up an insane amount of storage. Methods such as #send are only available on the GuildMember class (as opposed to the GuildMember class turned into an object by quick.db), so you can't access it from the db.

Instead, store the user ID in the db, as it's a unique identifier and you can get the user from it without storing huge objects in a db. You can use client.users.fetch(id) to get the user.

// await db.set('channel_id', 'author_id');

const id = await db.get('channel_id');
const user = await client.users.fetch(id);

user.send(...);
Lioness100
  • 8,260
  • 6
  • 18
  • 49
0

Ok I fixed thanks to @Lioness100

Heres what I did

const memberid = db.fetch(`ticket_${message.channel.id}`)
            const user =  message.guild.members.cache.find(c=> c.id === memberid)

Works fine! :) Thanks for helping guys.

Chuli
  • 3
  • 1
  • Use `Collection#get()` when searching by IDs (`members.cache.get(memberid)`). Also, if my answer solved your problem please mark it as accepted so it's easier for others who have the same problem to find in the future – Lioness100 May 12 '21 at 14:49