index.js
:const fs = require('node:fs');
const path = require('node:path');
const {Client, IntentsBitField, Collection} = require('discord.js');
const {token} = require('./config.json');
const myIntents = new IntentsBitField();
myIntents.add(IntentsBitField.Flags.GuildPresences, IntentsBitField.Flags.GuildMembers);
const client = new Client({intents: myIntents})
client.commands = new Collection();
const commandsPath = path.join(__dirname, 'commands');
const commandFiles = fs.readdirSync(commandsPath).filter(file => file.endsWith('.js'));
for (const file of commandFiles) {
const filePath = path.join(commandsPath, file);
const command = require(filePath);
// Set a new item in the Collection
// With the key as the command name and the value as the exported module
client.commands.set(command.data.name, command);
}
client.once('ready', () => {
console.log('Ready!');
client.user.setStatus("dnd")
});
client.on('interactionCreate', async interaction => {
if (!interaction.isChatInputCommand()) return;
const command = client.commands.get(interaction.commandName);
if (!command) {
await interaction.reply('Команда не найдена');
return
}
try {
await command.execute(interaction);
} catch (error) {
console.error(error);
await interaction.reply({content: 'Произошла ошибка в команде. Попробуйте позже.', ephemeral: true});
}
});
client.login(token);
const {SlashCommandBuilder, EmbedBuilder, Message} = require('discord.js');
module.exports = {
data: new SlashCommandBuilder()
.setName('user')
.setDescription('Получите информацию о пользователе')
.addUserOption(option =>
option.setName('mention')
.setDescription('Упоминание нужного пользователя')
.setRequired(false)),
async execute(interaction) {
const obj = {
"online": "Онлайн",
"offline": "Оффлайн",
"invisible": "Невидимый",
"dnd": "Не беспокоить",
"idle": "Неактивен"
} // словарь
let user = interaction.options.getUser('mention')
let member = interaction.options.getMember('mention')
if(!user) {
user = interaction.user
member = interaction.member
}
const avatar = user.avatarURL()
const embed = new EmbedBuilder()
.setColor(0x0099FF)
.setAuthor({ name: `Информация о ${user.username}`, iconURL: avatar})
.setThumbnail(avatar)
.addFields({
name: "Основная информация",
value: `**Имя пользователя:** ${user.username} \n**ID:** ${user.id} \n**Статус:** ${obj[member.presence.status]} \n**Дата регистрации:** ${user.createdAt}`
})
interaction.reply({embeds: [embed]})
}
}
TypeError: Cannot read properties of null (reading 'status')
at Object.execute (/home/nikita/botfordownloadapk/commands/user.js:34:121)
at Client.<anonymous> (/home/nikita/botfordownloadapk/index.js:37:23)
at Client.emit (node:events:513:28)
at InteractionCreateAction.handle (/home/nikita/botfordownloadapk/node_modules/discord.js/src/client/actions/InteractionCreate.js:81:12)
at module.exports [as INTERACTION_CREATE] (/home/nikita/botfordownloadapk/node_modules/discord.js/src/client/websocket/handlers/INTERACTION_CREATE.js:4:36)
at WebSocketManager.handlePacket (/home/nikita/botfordownloadapk/node_modules/discord.js/src/client/websocket/WebSocketManager.js:352:31)
at WebSocketShard.onPacket (/home/nikita/botfordownloadapk/node_modules/discord.js/src/client/websocket/WebSocketShard.js:481:22)
at WebSocketShard.onMessage (/home/nikita/botfordownloadapk/node_modules/discord.js/src/client/websocket/WebSocketShard.js:321:10)
at WebSocket.onMessage (/home/nikita/botfordownloadapk/node_modules/ws/lib/event-target.js:199:18)
at WebSocket.emit (node:events:513:28)
interaction.member.presence.status
Итог: эта ошибка.