I want to start my Bot but it dont work and i tried already the most things but nothing worked for me. I hope you can help me
The Code:
client.on('ready', async () => {
log.success(`Authenticated as ${client.user.tag}`);
client.user.setPresence({
activity: {
name: env.PRESENCE_ACTIVITY,
type: env.PRESENCE_TYPE.toUpperCase()
}
})
if (client.guilds.cache.get(env.GUILD_ID).member(client.user).hasPermission('ADMINISTRATOR', false)) {
log.success('Bot has the \'ADMINISTRATOR\' permission');
} else log.warn('Bot does not have \'ADMINISTRATOR\' permission');
client.guilds.cache.get(env.GUILD_ID).roles.fetch().then((roles) => {
purchasedRole = roles.cache.get(env.PURCHASED_ROLE_ID);
});
});
Error:
TypeError: Cannot read properties of undefined (reading 'member')
at Client.<anonymous> (C:\Users\User\Desktop\Discord-Bot\index.js:308:46)
at Client.emit (node:events:527:28)
at WebSocketManager.triggerClientReady (C:\Users\User\Desktop\Discord-Bot\node_modules\discord.js\src\client\websocket\WebSocketManager.js:431:17)
at WebSocketManager.checkShardsReady (C:\Users\User\Desktop\Discord-Bot\node_modules\discord.js\src\client\websocket\WebSocketManager.js:415:10)
at WebSocketShard.<anonymous> (C:\Users\User\Desktop\Discord-Bot\node_modules\discord.js\src\client\websocket\WebSocketManager.js:197:14)
at WebSocketShard.emit (node:events:527:28)
at WebSocketShard.checkReady (C:\Users\User\Desktop\Discord-Bot\node_modules\discord.js\src\client\websocket\WebSocketShard.js:475:12)
at WebSocketShard.onPacket (C:\Users\User\Desktop\Discord-Bot\node_modules\discord.js\src\client\websocket\WebSocketShard.js:447:16)
at WebSocketShard.onMessage (C:\Users\User\Desktop\Discord-Bot\node_modules\discord.js\src\client\websocket\WebSocketShard.js:301:10)
at WebSocket.onMessage (C:\Users\User\Desktop\Discord-Bot\node_modules\ws\lib\event-target.js:132:16)
Can someone help?
You have a typo in client.guilds.cache.get(env.GUILD_ID).member(client.user)
.
Its not member
its the plural members
as you can see here
I don't know if client.user
works here so maybe try client.user.id
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.