'Error on javascript while creating a ds b0t

 if (button.id == 'AddVerifiedRole') {
     button.reply.send(`Verified!`, true)
     const role = button.guild.roles.cache.get(config.roleid)
     const member = button.clicker.member
     await member.roles.add(role)
 }{}
}) 

I Want to do a verification system with a discord bot. If i press on Verify somethimes the bot crash whit this error :

   await member.roles.add(role)
                  ^

TypeError: Cannot read properties of null (reading 'roles')
   at Client.<anonymous> (C:\bot\TestBot\index.js:28:20)
   at Client.emit (node:events:526:28)
   at WebSocketManager.<anonymous> (C:\bot\TestBot\node_modules\discord-buttons\src\index.js:35:16)
   at WebSocketManager.emit (node:events:526:28)
   at WebSocketShard.onMessage (C:\bot\TestBot\node_modules\discord.js\src\client\websocket\WebSocketShard.js:296:56)
   at WebSocket.onMessage (C:\bot\TestBot\node_modules\ws\lib\event-target.js:132:16)
   at WebSocket.emit (node:events:526:28)
   at Receiver.receiverOnMessage (C:\bot\TestBot\node_modules\ws\lib\websocket.js:970:20)
   at Receiver.emit (node:events:526:28)
   at Receiver.dataMessage (C:\bot\TestBot\node_modules\ws\lib\receiver.js:517:14)

Can somebody help me?


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source