Выдаёт TypeError при отправке сообщения участнику, отправляет 1 раз, и сразу выдаёт ошибку, причем из main файла. Сразу говорю я писал сообщение боту не в личку. Мой код:
const Discord = module.require('discord.js')
const fs = require('fs')
const { send } = require('process')
module.exports.run = async (client,message,args) => {
let rUser = message.guild.member(message.mentions.users.first() || message.guild.members.get(args[0]));
if (rUser){
rUser.createDM()
rUser.send("hh")
}
}
module.exports.help = {
name: 'тест'
}
Мой main файл откуда исходит ошибка:
const Discord = require('discord.js')
const fs = require('fs')
const client = new Discord.Client()
const config = require('./config.json')
let prefixes = require('./prefixes.json')
const fetch = require('node-fetch')
let profile = require('./profile.json')
client.commands = new Discord.Collection()
fs.readdir('./commands', (err, files) => {
if (err) console.log(err)
let jsfile = files.filter(f => f.split('.').pop() === 'js')
if (jsfile.length <= 0) return message.channel.send("Команды не найдены!")
console.log(`Загружено ${jsfile.length} команд`)
jsfile.forEach((f, i) => {
let props = require(`./commands/${f}`)
client.commands.set(props.help.name, props)
})
})
client.on('ready', () => {
console.log(`Бот ${client.user.username} запустился`);
client.user.setPresence({
status: 'online',
activity: {
type: 'STREAMING',
name: '.help',
}
})
})
client.on('message', message => {
let sid = message.guild.id
let uid = message.author.id
if(!prefixes[sid]){
prefixes[sid] ={
prefix:'.',
};
};
let prefix = prefixes[sid].prefix
fs.writeFile('./prefixes.json',JSON.stringify(prefixes),(err)=>{
if (err) console.log(err)
})
if(!profile[uid]){
profile[uid] ={
warns:0,
};
};
fs.writeFile('./profile.json',JSON.stringify(profile),(err)=>{
if (err) console.log(err)
})
if (!message.content.startsWith(prefix) || message.author.bot) return;
let messageArray = message.content.split(' ')
let command = messageArray[0]
let args = messageArray.slice(1)
let command_file = client.commands.get(command.slice(prefix.length))
if (command_file) command_file.run(client, message, args, prefix)
})
client.login(config.token)
Выдаёт такую ошибку:
let sid = message.guild.id
^
TypeError: Cannot read property 'id' of null
at Client.<anonymous> (C:\Users\User\MyBot\bot.js:35:29)
at Client.emit (events.js:376:20)
at MessageCreateAction.handle (C:\Users\User\MyBot\node_modules\discord.js\src\client\actions\MessageCreate.js:31:14)
at Object.module.exports [as MESSAGE_CREATE] (C:\Users\User\MyBot\node_modules\discord.js\src\client\websocket\handlers\MESSAGE_CREATE.js:4:32)
at WebSocketManager.handlePacket (C:\Users\User\MyBot\node_modules\discord.js\src\client\websocket\WebSocketManager.js:384:31)
at WebSocketShard.onPacket (C:\Users\User\MyBot\node_modules\discord.js\src\client\websocket\WebSocketShard.js:444:22)
at WebSocketShard.onMessage (C:\Users\User\MyBot\node_modules\discord.js\src\client\websocket\WebSocketShard.js:301:10)
at WebSocket.onMessage (C:\Users\User\MyBot\node_modules\ws\lib\event-target.js:132:16)
at WebSocket.emit (events.js:376:20)
at Receiver.receiverOnMessage (C:\Users\User\MyBot\node_modules\ws\lib\websocket.js:834:20)