KrystStalin
KrystStalin

Reputation: 21

Trying to find channel by name

I'm trying to find a channel named "raidprotect-logs" on my server, by name, with my bot. But, it throws me the error ReferenceError: msg is not defined. I put this code in bot.on('ready', () => {.

This is my code:

const logChannel = msg.client.channels.find('raidprotect-logs', channelName)
logChannel.send(logEmbed)

So, my main question is : How can I define msg ?

(I declared logEmbed properly before those lines)

I tried to put it in bot.on('message', msg => { section but it throws me the error ReferenceError: channelName is not defined. I think when I'll pass the msg is not defined error i'll have this one. I don't know how to define channelName.

Upvotes: 0

Views: 201

Answers (1)

Cipher
Cipher

Reputation: 2722

The message channel its a Discord collection, so you need use array map to find it. You can get channel with 2 methods, second the better.

bot.on('message', msg => {
    logChannel = msg.guild.channels.find(channel => channel.name === 'raidprotect-logs') // Find method 
    LogChannel = bot.channels.get('CHANNELID HERE') //Best way 
}

Upvotes: 1

Related Questions