Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
249 views
in Technique[技术] by (71.8m points)

javascript - Discord Bot - member is not defined

This is my code:

bot.on('message', (message) => { //whenever a message is sent
    if (message.content.includes('discord.gg/'||'discordapp.com/invite/')) { //if it contains an invite link
      message.delete() //delete the message
        .then(message.channel.send(`**Hey <@${member.id}>! Don't Share Server Links.**`))
    }
  })

And I receive the following error:

.then(message.channel.send(`**Hey <@${member.id}>! Sunucu Linki Payla?mamal?s?n.**`))
                                              ^

ReferenceError: member is not defined
    at Client.<anonymous> (C:UsersulaumOneDriveMasaüstüLeet BOTot.js:18:47)
    at Client.emit (node:events:391:22)
    at MessageCreateAction.handle (C:UsersulaumOneDriveMasaüstüLeet BOT
ode_modulesdiscord.jssrcclientactionsMessageCreate.js:31:14)
    at Object.module.exports [as MESSAGE_CREATE] (C:UsersulaumOneDriveMasaüstüLeet BOT
ode_modulesdiscord.jssrcclientwebsockethandlersMESSAGE_CREATE.js:4:32)
    at WebSocketManager.handlePacket (C:UsersulaumOneDriveMasaüstüLeet BOT
ode_modulesdiscord.jssrcclientwebsocketWebSocketManager.js:384:31)
    at WebSocketShard.onPacket (C:UsersulaumOneDriveMasaüstüLeet BOT
ode_modulesdiscord.jssrcclientwebsocketWebSocketShard.js:444:22)
    at WebSocketShard.onMessage (C:UsersulaumOneDriveMasaüstüLeet BOT
ode_modulesdiscord.jssrcclientwebsocketWebSocketShard.js:301:10)
    at WebSocket.onMessage (C:UsersulaumOneDriveMasaüstüLeet BOT
ode_moduleswslibevent-target.js:132:16)
    at WebSocket.emit (node:events:379:20)
    at Receiver.receiverOnMessage (C:UsersulaumOneDriveMasaüstüLeet BOT
ode_moduleswslibwebsocket.js:825:20
question from:https://stackoverflow.com/questions/65871879/discord-bot-member-is-not-defined

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

member is not defined as the error already mentioned. This means there is no variable called member. You could change your code into:

bot.on('message', (message) => { //whenever a message is sent
    if (message.content.includes('discord.gg/'||'discordapp.com/invite/')) { //if it contains an invite link
      message.delete() //delete the message
        .then(message.channel.send(`**Hey <@${message.author.id}>! Don't Share Server Links.**`))
    }
  })

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...