Sheepboi546
Sheepboi546
DIAdiscord.js - Imagine an app
Created by Sheepboi546 on 9/13/2024 in #djs-questions
How can I ban people with my bot who are outside of the server? (reopening)
I still cannot seem to find away to ban users who are outside of my server and require help Im currently using an embed which you can choose if you want to ban or kick a person, which then goes to the button script to do the rest command script:
const { SlashCommandBuilder, EmbedBuilder, PermissionFlagsBits, ActionRowBuilder, ButtonBuilder, ButtonStyle } = require('discord.js');
const mConfig = require('../../messageConfig.json');
const moderationSchema = require("../../schemas/moderation");

module.exports = {
data: new SlashCommandBuilder()
.setName("moderate")
.setDescription("Moderate a server user.")
.addUserOption((o) => o
.setName("user")
.setDescription("The user you want to moderate.")
.setRequired(true)
)
.toJSON(),

userPermissions: [PermissionFlagsBits.Administrator],
botPermissions: [],

run: async (client, interaction) => {
const { options, guildId, guild, member } = interaction;

const user = options.getUser("user");
const targetMember = await guild.members.fetch(user.id);

const rEmbed = new EmbedBuilder()
.setColor("FF0000")
.setFooter({ text: `${client.user.username} - Advanced Moderation System` });

// Check if moderation system exists
let data = await moderationSchema.findOne({ GuildID: guildId });
if (!data) {
rEmbed.setColor(mConfig.embedColorError)
.setDescription("Moderation system not found! Please configure it using `/moderatesystem configure`.");
return interaction.reply({ embeds: [rEmbed], ephemeral: true });
}

// Prevent moderating oneself
if (targetMember.id === member.id) {
rEmbed.setColor(mConfig.embedColorError)
.setDescription(`${mConfig.unableToInteractWithYourself}`);
return interaction.reply({ embeds: [rEmbed], ephemeral: true });
}

// Check role hierarchy
if (targetMember.roles.highest.position >= member.roles.highest.position) {
rEmbed.setColor(mConfig.embedColorError)
.setDescription(`${mConfig.hasHigherRolePosition}`);
return interaction.reply({ embeds: [rEmbed], ephemeral: true });
}

// Check if the member has the required role
const requiredRole = member.guild.roles.cache.find(role => role.name === "G Bot Permissions");
if (!requiredRole || !member.roles.cache.has(requiredRole.id)) {
const roleEmbed = new EmbedBuilder()
.setColor(mConfig.embedColorError)
.setDescription("You do not have the required role to use this command.");
return interaction.reply({ embeds: [roleEmbed], ephemeral: true });
}

const moderationButtons = new ActionRowBuilder().setComponents(
new ButtonBuilder().setCustomId("banBtn").setLabel("Server Ban").setStyle(ButtonStyle.Danger),
new ButtonBuilder().setCustomId("kickBtn").setLabel("Server Kick").setStyle(ButtonStyle.Danger),
new ButtonBuilder().setCustomId("cancelBtn").setLabel("Cancel").setStyle(ButtonStyle.Secondary),
);

rEmbed.setAuthor({
name: `${targetMember.user.username}`,
iconURL: `${targetMember.user.displayAvatarURL({ dynamic: true })}`
}).setDescription(`What action would you like to perform on: ${targetMember.user.username}?`);

interaction.reply({ embeds: [rEmbed], components: [moderationButtons] });
},
};
const { SlashCommandBuilder, EmbedBuilder, PermissionFlagsBits, ActionRowBuilder, ButtonBuilder, ButtonStyle } = require('discord.js');
const mConfig = require('../../messageConfig.json');
const moderationSchema = require("../../schemas/moderation");

module.exports = {
data: new SlashCommandBuilder()
.setName("moderate")
.setDescription("Moderate a server user.")
.addUserOption((o) => o
.setName("user")
.setDescription("The user you want to moderate.")
.setRequired(true)
)
.toJSON(),

userPermissions: [PermissionFlagsBits.Administrator],
botPermissions: [],

run: async (client, interaction) => {
const { options, guildId, guild, member } = interaction;

const user = options.getUser("user");
const targetMember = await guild.members.fetch(user.id);

const rEmbed = new EmbedBuilder()
.setColor("FF0000")
.setFooter({ text: `${client.user.username} - Advanced Moderation System` });

// Check if moderation system exists
let data = await moderationSchema.findOne({ GuildID: guildId });
if (!data) {
rEmbed.setColor(mConfig.embedColorError)
.setDescription("Moderation system not found! Please configure it using `/moderatesystem configure`.");
return interaction.reply({ embeds: [rEmbed], ephemeral: true });
}

// Prevent moderating oneself
if (targetMember.id === member.id) {
rEmbed.setColor(mConfig.embedColorError)
.setDescription(`${mConfig.unableToInteractWithYourself}`);
return interaction.reply({ embeds: [rEmbed], ephemeral: true });
}

// Check role hierarchy
if (targetMember.roles.highest.position >= member.roles.highest.position) {
rEmbed.setColor(mConfig.embedColorError)
.setDescription(`${mConfig.hasHigherRolePosition}`);
return interaction.reply({ embeds: [rEmbed], ephemeral: true });
}

// Check if the member has the required role
const requiredRole = member.guild.roles.cache.find(role => role.name === "G Bot Permissions");
if (!requiredRole || !member.roles.cache.has(requiredRole.id)) {
const roleEmbed = new EmbedBuilder()
.setColor(mConfig.embedColorError)
.setDescription("You do not have the required role to use this command.");
return interaction.reply({ embeds: [roleEmbed], ephemeral: true });
}

const moderationButtons = new ActionRowBuilder().setComponents(
new ButtonBuilder().setCustomId("banBtn").setLabel("Server Ban").setStyle(ButtonStyle.Danger),
new ButtonBuilder().setCustomId("kickBtn").setLabel("Server Kick").setStyle(ButtonStyle.Danger),
new ButtonBuilder().setCustomId("cancelBtn").setLabel("Cancel").setStyle(ButtonStyle.Secondary),
);

rEmbed.setAuthor({
name: `${targetMember.user.username}`,
iconURL: `${targetMember.user.displayAvatarURL({ dynamic: true })}`
}).setDescription(`What action would you like to perform on: ${targetMember.user.username}?`);

interaction.reply({ embeds: [rEmbed], components: [moderationButtons] });
},
};
74 replies
DIAdiscord.js - Imagine an app
Created by Sheepboi546 on 9/13/2024 in #djs-questions
How can I ban people with my bot who are outside of the server?
I’ve managed to do a guild command but I cannot manage to make it so I can ban people outside of the guild, how do can I make it do that?
5 replies
DIAdiscord.js - Imagine an app
Created by Sheepboi546 on 9/8/2024 in #djs-questions
how can I fix my bots latency?
How can I improve my bots latency, it’s averaging about 600ms and it would be nice to be lower (sometimes goes up to 5000ms) I’m using Ethernet on an extender
5 replies
DIAdiscord.js - Imagine an app
Created by Sheepboi546 on 9/4/2024 in #djs-questions
connection timeout error constantly
I keep getting a connection timeout error on my discord bot while hosting it and I don’t know how to fix it I’ve tried pm2 etc and it still dosent work how would one proceed? (I don’t want to pay for hosting as I try to be as tight on money as possible)
7 replies