TypeError: Cannot read properties of undefined (reading 'channels')

I am trying to automate the welcome messages through the use of a bot and have a functioning listener for the guildMemberAdd event but when trying to get the id of the channel I want to send the message to I get this error. My code is the following
import { Listener } from "@sapphire/framework";
import { Client, TextChannel } from "discord.js";


export class GuildMemberAddGreeting extends Listener {
public constructor(context: Listener.Context, options: Listener.Options) {
super(context, {
...options,
event: 'guildMemberAdd',
once: false
});
}

public override async run(client: Client) {
//CHANGE ONCE MOVED TO ACM SERVER
const channel = client.channels.cache.get('1115435350060445817');
}
}
import { Listener } from "@sapphire/framework";
import { Client, TextChannel } from "discord.js";


export class GuildMemberAddGreeting extends Listener {
public constructor(context: Listener.Context, options: Listener.Options) {
super(context, {
...options,
event: 'guildMemberAdd',
once: false
});
}

public override async run(client: Client) {
//CHANGE ONCE MOVED TO ACM SERVER
const channel = client.channels.cache.get('1115435350060445817');
}
}
I have at this point quintuple checked that this is the correct channel and correct id for the channel. Does this have something to do with the nature of the client object being passed in. Any help appreciated.
5 Replies
b1nzee
b1nzee16mo ago
client isn't a parameter for guildMemberAdd Also this is a discord.js issue, not sapphire related But nevertheless, the argument should be member (as it's the GuildMember passed through) And just like in a Command class, you can use
this.container.client.channels.cache.get()
this.container.client.channels.cache.get()
As container is also part of the Listener class
Clartye
Clartye16mo ago
Ahh ok that makes more sense that it takes the guild member rather than the client. I struggled to find info on the docs I am not super experience reading docs in general but do you have alink to the documentation for the listener class. When using the search function on the site I only see the namespace Listener.
b1nzee
b1nzee16mo ago
And as for discord.js documentation, the event shows the parameter being "member"
Favna
Favna16mo ago
Also if you do Listener<typeof Events.GuildMemberAdd> (Events is imported from sapphire, it's our constant for all the event names, you can also use it for the event: Events.GuildMemberAdd) then TS will scream at you for providing the wrong types to the run method.
Want results from more Discord servers?
Add your server