commit
This commit is contained in:
parent
8a23e86b12
commit
f6e5d49159
4 changed files with 57 additions and 6 deletions
|
@ -1,5 +1,5 @@
|
|||
import { SlashCommandBuilder, CommandInteraction, PermissionsBitField } from "discord.js";
|
||||
import { connectToDb, getguild, addGuild } from "../../libs/mysql.js"
|
||||
import { connectToDb, getGuild, addGuild } from "../../libs/mysql.js"
|
||||
import { errorEmbed, successEmbed } from "../../libs/discord.js";
|
||||
|
||||
export default {
|
||||
|
@ -11,7 +11,7 @@ export default {
|
|||
const guild_id: string = interaction.guildId ? interaction.guildId : "";
|
||||
const member = interaction.guild?.members.cache.get(interaction.user.id);
|
||||
|
||||
if (! member?.permissions.has(PermissionsBitField.Flags.ManageGuild)) {
|
||||
if (!member?.permissions.has(PermissionsBitField.Flags.ManageGuild)) {
|
||||
const embed = errorEmbed("You are not allowed to use that command.", interaction.client.user.displayAvatarURL());
|
||||
|
||||
return await interaction.reply({embeds: [embed]});
|
||||
|
@ -19,7 +19,7 @@ export default {
|
|||
|
||||
const connection = await connectToDb();
|
||||
|
||||
const guild: any[] = await getguild(connection, guild_id);
|
||||
const guild: any[] = await getGuild(connection, guild_id);
|
||||
|
||||
if (guild[0]) {
|
||||
const embed = await errorEmbed("Your server is already registered.", interaction.client.user.displayAvatarURL());
|
||||
|
|
39
src/commands/guilds/setAdminRole.ts
Normal file
39
src/commands/guilds/setAdminRole.ts
Normal file
|
@ -0,0 +1,39 @@
|
|||
import { SlashCommandBuilder, ChatInputCommandInteraction, PermissionsBitField } from "discord.js";
|
||||
import { connectToDb, getGuild, setAdminRole } from "../../libs/mysql.js"
|
||||
import { errorEmbed, successEmbed } from "../../libs/discord.js";
|
||||
|
||||
|
||||
export default {
|
||||
data: new SlashCommandBuilder()
|
||||
.setName("setadminrole")
|
||||
.setDescription("Set the admin role for the bot")
|
||||
.addRoleOption(option => option.setName("role").setDescription("The role to be admin.").setRequired(true)),
|
||||
async execute(interaction: ChatInputCommandInteraction) {
|
||||
const guild_id: string = interaction.guildId ? interaction.guildId : "";
|
||||
const member = interaction.guild?.members.cache.get(interaction.user.id);
|
||||
|
||||
if (!member?.permissions.has(PermissionsBitField.Flags.ManageGuild)) {
|
||||
const embed = errorEmbed("You are not allowed to use that command.", interaction.client.user.displayAvatarURL());
|
||||
|
||||
return await interaction.reply({embeds: [embed]});
|
||||
}
|
||||
|
||||
const connection = await connectToDb();
|
||||
|
||||
const guild: any[] = await getGuild(connection, guild_id);
|
||||
|
||||
if (!guild[0]) {
|
||||
const embed = errorEmbed("Your server must be registered to the bot, use /register to do so.", interaction.client.user.displayAvatarURL());
|
||||
|
||||
return interaction.reply({embeds: [embed]});
|
||||
}
|
||||
|
||||
const role_id: string | undefined = interaction.options.getRole("role")?.id
|
||||
|
||||
await setAdminRole(connection, guild_id, role_id ? role_id : "");
|
||||
|
||||
const embed = successEmbed("The bot admin role has been successfully changed.", interaction.client.user.displayAvatarURL())
|
||||
|
||||
interaction.reply({embeds: [embed]})
|
||||
},
|
||||
};
|
|
@ -1,11 +1,11 @@
|
|||
import { Events, Guild } from "discord.js";
|
||||
import { connectToDb, getguild, addGuild } from "../libs/mysql.js";
|
||||
import { connectToDb, getGuild, addGuild } from "../libs/mysql.js";
|
||||
|
||||
export default {
|
||||
name: Events.GuildCreate,
|
||||
async execute(guild: Guild) {
|
||||
const connection = await connectToDb();
|
||||
const guild_obj: any[] = await getguild(connection, guild.id);
|
||||
const guild_obj: any[] = await getGuild(connection, guild.id);
|
||||
|
||||
connection.end()
|
||||
|
||||
|
|
|
@ -74,7 +74,7 @@ export function resetQuota(connection: mysql.Connection) {
|
|||
})
|
||||
}
|
||||
|
||||
export function getguild(connection: mysql.Connection, guild_id: string): Promise<any[]> {
|
||||
export function getGuild(connection: mysql.Connection, guild_id: string): Promise<any[]> {
|
||||
return new Promise((resolve, reject) => {
|
||||
connection.query(`SELECT * FROM guilds WHERE guild_id = "${guild_id}"`, (error, result) => {
|
||||
if (error) {
|
||||
|
@ -97,3 +97,15 @@ export function addGuild(connection: mysql.Connection, guild_id: string) {
|
|||
})
|
||||
})
|
||||
}
|
||||
|
||||
export function setAdminRole(connection: mysql.Connection, guild_id: string, role_id: string) {
|
||||
return new Promise((resolve, reject) => {
|
||||
connection.query(`UPDATE guilds SET admin_role_id = "${role_id}" WHERE guild_id = "${guild_id}"`, (error, result) => {
|
||||
if (error) {
|
||||
reject(error);
|
||||
}
|
||||
|
||||
resolve(result);
|
||||
})
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue