I have a trouble, that I can't understand at all. The function working on my server, and not working on another one. Here's my code:
const user = message.author;
let servericon = message.guild.iconURL;
let serverembed = new Discord.MessageEmbed()
.setAuthor(message.author.username, auser.displayAvatarURL({ format: 'png' }))
.setTitle("Информация о сервере")
.setColor("RANDOM")
.setThumbnail(servericon)
.addField("Название сервера :", message.guild.name)
.addField("Владелец :", `${message.guild.owner.user.tag}`, true)
.addField("Каналы :", message.guild.channels.cache.size, true)
.addField("Роли :", message.guild.roles.cache.size, true)
.addField("Сервер создан :", `${moment(message.guild.createdAt).format('MMMM Do YYYY')}`)
.addField("Пользователей :", message.guild.memberCount)
.setThumbnail(message.guild.iconURL())
.setTimestamp()
message.channel.send(serverembed);
And error is:
(node:11288) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'user' of null
at Object.run (C:\Users\alumetryu\Desktop\bot\commands\info\serverinfo.js:20:48)
at Client. (C:\Users\alumetryu\Desktop\bot\ame\index.js:38:17)
at Client.emit (events.js:315:20)
at MessageCreateAction.handle (C:\Users\alumetryu\node_modules\discord.js\src\client\actions\MessageCreate.js:31:14)
at Object.module.exports [as MESSAGE_CREATE] (C:\Users\alumetryu\node_modules\discord.js\src\client\websocket\handlers\MESSAGE_CREATE.js:4:32)
at WebSocketManager.handlePacket (C:\Users\alumetryu\node_modules\discord.js\src\client\websocket\WebSocketManager.js:384:31)
at WebSocketShard.onPacket (C:\Users\alumetryu\node_modules\discord.js\src\client\websocket\WebSocketShard.js:444:22)
at WebSocketShard.onMessage (C:\Users\alumetryu\node_modules\discord.js\src\client\websocket\WebSocketShard.js:301:10)
at WebSocket.onMessage (C:\Users\alumetryu\node_modules\ws\lib\event-target.js:125:16)
at WebSocket.emit (events.js:315:20)
at Receiver.receiverOnMessage (C:\Users\alumetryu\node_modules\ws\lib\websocket.js:797:20)
at Receiver.emit (events.js:315:20)
at Receiver.dataMessage (C:\Users\alumetryu\node_modules\ws\lib\receiver.js:437:14)
at Receiver.getData (C:\Users\alumetryu\node_modules\ws\lib\receiver.js:367:17)
at Receiver.startLoop (C:\Users\alumetryu\node_modules\ws\lib\receiver.js:143:22)
at Receiver._write (C:\Users\alumetryu\node_modules\ws\lib\receiver.js:78:10)
at doWrite (_stream_writable.js:403:12)
at writeOrBuffer (_stream_writable.js:387:5)
at Receiver.Writable.write (_stream_writable.js:318:11)
at TLSSocket.socketOnData (C:\Users\alumetryu\node_modules\ws\lib\websocket.js:872:35)
at TLSSocket.emit (events.js:315:20)
at addChunk (_stream_readable.js:295:12)
(node:11288) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag --unhandled-rejections=strict
(see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:11288) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
message.guild.owner
is null, you could check if it's null,addField("Владелец :", `${(message.guild.owner ? message.guild.owner.user.tag : "-")}`, true)
– Shoejep