So, my server has channels for each user, and the name of the channel is their user id.
The way I want it to work is;
When a user DMs the bot with any message, the bot looks for that channel (the channel that's named as their user id) in the server and sends the content of the message it receieved in DMs, but I keep getting an error:
Cannot read property "send" of undefined
Here is my code
client.on("message", async (message) => {
if (message.channel.type === "dm") {
if (message.author.bot) return;
var guild = client.guilds.cache.get("840120593311334410");
const cha = message.author.id;
var hsa = await guild.channels.cache.find((ch) => ch.name === cha);
hsa.send("test");
}
});
There are 2 types of problems I have for you:
GuildChannelManager.fetch() to cache all the channels. var guild = client.guilds.cache.get("840120593311334410");
const cha = message.author.id;
await guild.channels.fetch(); //ONLY NEW LINE
var hsa = await guild.channels.cache.find((ch) => ch.name === cha);
hsa.send("test");