/|ĶÎŦÃŖŮ|\
/|ĶÎŦÃŖŮ|\
DIAdiscord.js - Imagine an app
Created by /|ĶÎŦÃŖŮ|\ on 2/27/2024 in #djs-questions
Question about getting a user from his ID
In short I get the userid from the database with mutes and pass it to const member = guild.members.cache.get(row.id); but when the bot needs to remove the role, it logs me an error: 02/27 11:14:01 [Bot] member.roles.remove(mutedRoleId); 27.02 11:14:01 [Bot] ^ 02/27 11:14:01 [Bot] TypeError: Cannot read properties of undefined (reading 'roles')
25 replies
DIAdiscord.js - Imagine an app
Created by /|ĶÎŦÃŖŮ|\ on 2/26/2024 in #djs-questions
Trouble with fetch roles in command
No description
5 replies
DIAdiscord.js - Imagine an app
Created by /|ĶÎŦÃŖŮ|\ on 2/26/2024 in #djs-questions
Sorry if this is off topic.
Sorry if this is off topic, I would like to ask you to evaluate the code and, if possible, suggest what to work on.
const { EmbedBuilder } = require('discord.js');

const unPermissionEmb = (interaction) => new EmbedBuilder()
.setColor('#ff0000')
.setTitle('У вас недостаточно прав для использования этой команды!')
.setDescription('Если это баг сообщите кому-нибудь из персонала.')
.setThumbnail(interaction.user.displayAvatarURL().toString());

const CommandHandlerErrorEmb = (interaction) => new EmbedBuilder()
.setColor('#ff0000')
.setTitle('Ошибка при использовании этой команды!')
.addFields({ name: 'Команда: ', value: interaction.commandName, inline: true })
.setDescription ('Если это баг сообщите кому-нибудь из персонала.')
.setThumbnail(interaction.user.displayAvatarURL().toString());

module.exports = { unPermissionEmb, CommandHandlerErrorEmb };
const { EmbedBuilder } = require('discord.js');

const unPermissionEmb = (interaction) => new EmbedBuilder()
.setColor('#ff0000')
.setTitle('У вас недостаточно прав для использования этой команды!')
.setDescription('Если это баг сообщите кому-нибудь из персонала.')
.setThumbnail(interaction.user.displayAvatarURL().toString());

const CommandHandlerErrorEmb = (interaction) => new EmbedBuilder()
.setColor('#ff0000')
.setTitle('Ошибка при использовании этой команды!')
.addFields({ name: 'Команда: ', value: interaction.commandName, inline: true })
.setDescription ('Если это баг сообщите кому-нибудь из персонала.')
.setThumbnail(interaction.user.displayAvatarURL().toString());

module.exports = { unPermissionEmb, CommandHandlerErrorEmb };
const fs = require('node:fs');
const path = require('node:path');
const {Client, ButtonBuilder, ButtonStyle, StringSelectMenuBuilder, StringSelectMenuOptionBuilder, Events, SlashCommandBuilder, EmbedBuilder, ActionRowBuilder, ModalBuilder, ModalSubmitInteraction, TextInputBuilder, TextInputStyle } = require('discord.js');
const { PingEmb } = require('../../embeds/pingEmb.js');

const hierarchyPath = path.join(__dirname, '..', '..', 'configs', 'hierarchy.json');
const hierarchy = JSON.parse(fs.readFileSync(hierarchyPath, 'utf-8'));
const userRole = hierarchy.find(role => role.name === 'User');

module.exports = {
data: new SlashCommandBuilder()
.setName("ping")
.setDescription('Отправит "Понг!"')
.setNameLocalizations({
ru: 'пинг'
}),
hierarchy: userRole.permission,
async execute (interaction, client) {
interaction.reply({
embeds: [ PingEmb(interaction) ],
ephemeral: true
});
}
}
const fs = require('node:fs');
const path = require('node:path');
const {Client, ButtonBuilder, ButtonStyle, StringSelectMenuBuilder, StringSelectMenuOptionBuilder, Events, SlashCommandBuilder, EmbedBuilder, ActionRowBuilder, ModalBuilder, ModalSubmitInteraction, TextInputBuilder, TextInputStyle } = require('discord.js');
const { PingEmb } = require('../../embeds/pingEmb.js');

const hierarchyPath = path.join(__dirname, '..', '..', 'configs', 'hierarchy.json');
const hierarchy = JSON.parse(fs.readFileSync(hierarchyPath, 'utf-8'));
const userRole = hierarchy.find(role => role.name === 'User');

module.exports = {
data: new SlashCommandBuilder()
.setName("ping")
.setDescription('Отправит "Понг!"')
.setNameLocalizations({
ru: 'пинг'
}),
hierarchy: userRole.permission,
async execute (interaction, client) {
interaction.reply({
embeds: [ PingEmb(interaction) ],
ephemeral: true
});
}
}
At the moment I am training in code layering and structurization, I also try to optimize as much as possible, I know few functions, but they will tell you something.
2 replies
DIAdiscord.js - Imagine an app
Created by /|ĶÎŦÃŖŮ|\ on 2/19/2024 in #djs-questions
Counting voice
Uncorrected counting voice channels members
14 replies
DIAdiscord.js - Imagine an app
Created by /|ĶÎŦÃŖŮ|\ on 2/19/2024 in #djs-questions
The problem with counting users in voice channels
The problem with counting users in voice channels, the input to the channel works fine, but the output remains the highest value and the number does not decrease.
const bannerUpdate = async () => {
const totalMembers = guild.memberCount;
console.log(`Общее количество участников на сервере: ${totalMembers}`);

await guild.members.fetch();

let voiceMembers = guild.voiceStates.cache.filter(voiceState => !voiceState.member.user.bot).size;
console.log(`Количество участников в голосовых каналах: ${voiceMembers}`);

const banner = canvas.createCanvas(1920, 1080);
const context = banner.getContext('2d');

const background = await canvas.loadImage(path.join(__dirname, 'background.png'));
context.drawImage(background, 0, 0, banner.width, banner.height);

context.fillStyle = 'white';
context.shadowColor = 'pink';
context.textSpacing = 100;
context.shadowBlur = 120;
context.shadowOffsetX = 0;
context.shadowOffsetY = 0;
registerFont(require("@canvas-fonts/comic-sans-ms"), { family: "Comic Sans MS" });
context.font = '145px "Comic Sans MS"';
context.textAlign = 'center';
context.fillText(`${totalMembers}`, 1382.5, 375);
context.fillText(`${voiceMembers}`, 1382.5, 755);

context.globalCompositeOperation = 'lighter';
context.strokeStyle = 'pink';
context.lineWidth = 10;
context.textSpacing = 100;
context.strokeText(`${totalMembers}`, 1382.5, 375);
context.strokeText(`${voiceMembers}`, 1382.5, 755);

context.textSpacing = 100;

const bannerImage = banner.toBuffer()
guild.setBanner(bannerImage)
.then(updated => console.log(`Updated the banner of ${updated.name}`))
.catch(console.error);
};

bannerUpdate();

setInterval(bannerUpdate, 1 * 60 * 1000);
const bannerUpdate = async () => {
const totalMembers = guild.memberCount;
console.log(`Общее количество участников на сервере: ${totalMembers}`);

await guild.members.fetch();

let voiceMembers = guild.voiceStates.cache.filter(voiceState => !voiceState.member.user.bot).size;
console.log(`Количество участников в голосовых каналах: ${voiceMembers}`);

const banner = canvas.createCanvas(1920, 1080);
const context = banner.getContext('2d');

const background = await canvas.loadImage(path.join(__dirname, 'background.png'));
context.drawImage(background, 0, 0, banner.width, banner.height);

context.fillStyle = 'white';
context.shadowColor = 'pink';
context.textSpacing = 100;
context.shadowBlur = 120;
context.shadowOffsetX = 0;
context.shadowOffsetY = 0;
registerFont(require("@canvas-fonts/comic-sans-ms"), { family: "Comic Sans MS" });
context.font = '145px "Comic Sans MS"';
context.textAlign = 'center';
context.fillText(`${totalMembers}`, 1382.5, 375);
context.fillText(`${voiceMembers}`, 1382.5, 755);

context.globalCompositeOperation = 'lighter';
context.strokeStyle = 'pink';
context.lineWidth = 10;
context.textSpacing = 100;
context.strokeText(`${totalMembers}`, 1382.5, 375);
context.strokeText(`${voiceMembers}`, 1382.5, 755);

context.textSpacing = 100;

const bannerImage = banner.toBuffer()
guild.setBanner(bannerImage)
.then(updated => console.log(`Updated the banner of ${updated.name}`))
.catch(console.error);
};

bannerUpdate();

setInterval(bannerUpdate, 1 * 60 * 1000);
5 replies
DIAdiscord.js - Imagine an app
Created by /|ĶÎŦÃŖŮ|\ on 2/9/2024 in #djs-questions
I haven't fully figured out subcommands yet
const {ButtonBuilder, ButtonStyle, StringSelectMenuBuilder, StringSelectMenuOptionBuilder, Events, SlashCommandBuilder, EmbedBuilder, ActionRowBuilder, ModalBuilder, ModalSubmitInteraction, TextInputBuilder, TextInputStyle } = require('discord.js');
const sqlite3 = require('sqlite3').verbose();

module.exports = {
data: new SlashCommandBuilder()
.setName('bot')
.setDescription('Комнда для настройки бота на сервере, данная команда может быть использована только владельцем.') // Короткое описание
.setNameLocalizations({
ru: 'настройки'
})
.addSubcommand(subcommand =>
subcommand
.setName ('settings')
.setDescription ('Комнда для настройки бота на сервере, данная команда может быть использована только владельцем.')
.setNameLocalizations({
ru: 'бота'
})
),

async execute(interaction) {
const userRoles = interaction.member.roles.cache;
const requiredRole = '1199044634987462708';

if (!userRoles.has(requiredRole)) {
const errorEmbed = new EmbedBuilder()
.setColor('#FF0000')
.setTitle('Ошибка!')
.setDescription('У вас нет прав на использование данной команды')
.setThumbnail(interaction.user.displayAvatarURL().toString());
return await interaction.reply({embeds: [errorEmbed], ephemeral: true});
}

const embedOptions = {
color: 0x2d2d31,
title: `Настройка бота`,
description: `Здесь вы можете выбрать интересующие вас настройки.`,
thumbnail: {url: guild.displayAvatarURL().toString()},
}
await interaction.reply({embeds: [embedOptions]});
}
}
const {ButtonBuilder, ButtonStyle, StringSelectMenuBuilder, StringSelectMenuOptionBuilder, Events, SlashCommandBuilder, EmbedBuilder, ActionRowBuilder, ModalBuilder, ModalSubmitInteraction, TextInputBuilder, TextInputStyle } = require('discord.js');
const sqlite3 = require('sqlite3').verbose();

module.exports = {
data: new SlashCommandBuilder()
.setName('bot')
.setDescription('Комнда для настройки бота на сервере, данная команда может быть использована только владельцем.') // Короткое описание
.setNameLocalizations({
ru: 'настройки'
})
.addSubcommand(subcommand =>
subcommand
.setName ('settings')
.setDescription ('Комнда для настройки бота на сервере, данная команда может быть использована только владельцем.')
.setNameLocalizations({
ru: 'бота'
})
),

async execute(interaction) {
const userRoles = interaction.member.roles.cache;
const requiredRole = '1199044634987462708';

if (!userRoles.has(requiredRole)) {
const errorEmbed = new EmbedBuilder()
.setColor('#FF0000')
.setTitle('Ошибка!')
.setDescription('У вас нет прав на использование данной команды')
.setThumbnail(interaction.user.displayAvatarURL().toString());
return await interaction.reply({embeds: [errorEmbed], ephemeral: true});
}

const embedOptions = {
color: 0x2d2d31,
title: `Настройка бота`,
description: `Здесь вы можете выбрать интересующие вас настройки.`,
thumbnail: {url: guild.displayAvatarURL().toString()},
}
await interaction.reply({embeds: [embedOptions]});
}
}
This code of my command command wont show in server, could this be due to the fact that I do not have a file with the main command, but only with a subcommand?
18 replies
DIAdiscord.js - Imagine an app
Created by /|ĶÎŦÃŖŮ|\ on 2/9/2024 in #djs-questions
Please help me create a slash command
I have a problem when creating a slash command: I want to make it two separate words, but I am faced with the problem of not being able to put a space.
5 replies