简体   繁体   中英

Script of welcome / goodbye to discord js bot Error

He is giving me this script of welcome/goodbye to Discord error and he has already tried many things if someone helps me I would appreciate it very much, Thanks

module.exports = (client) => {
    const channelIdA = '718596514305277972'
    
    client.on('guildMemberAdd', (member) => {
       console.log("Se ha unido una nueva persona al servidor TPA")
       
         const messageA = `message`

          const channel = (channelIdA)
          channel.send(messageA)
       })
   }
   
   module.exports = (client) => {
    const channelIdB = '890891192995303424'
    
    client.on('guildMemberRemove', (member) => {
       console.log("Se ha salido una persona del servidor TPA")
       
         const messageB = `message`
          
          const channel = (channelIdB)
          channel.send(messageB)
    })
}

You are attempting to send a message to a channel by calling the .send() method. However, you are calling the method on a string. The send() method only exists on text based channels . To send a message to a specific channel, replace your message sending code with this

client.on("guildMemberAdd", members => {
 client.channels.cache.get("REPLACE WITH CHANNEL ID").send("message")
});

client.on("guildMemberRemove", members => {
 client.channels.cache.get("REPLACE WITH OTHER CHANNEL ID").send(" other message")
});

If the above does not work, try this: (works without cache)

client.on("guildMemberAdd", async (member) => {
 const channel = await client.channels.fetch("REPLACE WITH CHANNEL ID")
 channel.send(`${member.user.username}, welcome`)
});

client.on("guildMemberRemove", async (member) => {
 const channel = await client.channels.fetch("REPLACE WITH OTHER CHANNEL ID")
 channel.send(`${member.user.username} has left`)
});

You should be getting the channel using this . If you already have the channel in cache (something happened in the channel after the bot started), you can use the channels cache as well.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM