137 lines
4.5 KiB
JavaScript
137 lines
4.5 KiB
JavaScript
'use strict';
|
|
|
|
const { time } = require("discord.js");
|
|
const fs = require('node:fs');
|
|
const path = require('node:path');
|
|
|
|
const DB_PATH = path.join(__dirname, '../../../db.json');
|
|
|
|
const readDb = () => {
|
|
try {
|
|
return JSON.parse(fs.readFileSync(DB_PATH, 'utf8'));
|
|
} catch {
|
|
return {};
|
|
}
|
|
};
|
|
|
|
const writeDb = (db) => {
|
|
fs.writeFileSync(DB_PATH, JSON.stringify(db, null, 2), 'utf8');
|
|
};
|
|
|
|
module.exports = {
|
|
name: 'prefix',
|
|
description: 'change the server command prefix',
|
|
aliases: ['setprefix'],
|
|
usage: 'prefix <new prefix>',
|
|
execute: async (client, message, args = []) => {
|
|
var embed;
|
|
if (!message.guild) {
|
|
await message.reply({
|
|
embeds: [{
|
|
color: 0x8aa2b3,
|
|
title: '',
|
|
author: {
|
|
name: message.author.username,
|
|
icon_url: message.author.displayAvatarURL(),
|
|
},
|
|
description: '<:no:1481811955592466492> this command can only be used in a server!',
|
|
footer: {
|
|
text: `twitter @ ${message.guild.name}`,
|
|
icon_url: client.user.displayAvatarURL(),
|
|
},
|
|
timestamp: new Date()
|
|
}]
|
|
});
|
|
return;
|
|
}
|
|
|
|
if (!message.member?.permissions?.has('ManageGuild')) {
|
|
await message.reply({
|
|
embeds: [{
|
|
color: 0x8aa2b3,
|
|
title: '',
|
|
author: {
|
|
name: message.author.username,
|
|
icon_url: message.author.displayAvatarURL(),
|
|
},
|
|
description: '<:no:1481811955592466492> you do not have permissions to run this command!',
|
|
footer: {
|
|
text: `twitter @ ${message.guild.name}`,
|
|
icon_url: client.user.displayAvatarURL(),
|
|
},
|
|
timestamp: new Date()
|
|
}]
|
|
});
|
|
return;
|
|
}
|
|
|
|
let newPrefix = args[0];
|
|
if (!newPrefix) {
|
|
const parts = message.content.trim().split(/\s+/);
|
|
newPrefix = parts[1];
|
|
}
|
|
|
|
if (!newPrefix) {
|
|
await message.reply({
|
|
embeds: [{
|
|
color: 0x8aa2b3,
|
|
title: '',
|
|
author: {
|
|
name: message.author.username,
|
|
icon_url: message.author.displayAvatarURL(),
|
|
},
|
|
description: '<:no:1481811955592466492> you must provide a new prefix!',
|
|
footer: {
|
|
text: `twitter @ ${message.guild.name}`,
|
|
icon_url: client.user.displayAvatarURL(),
|
|
},
|
|
timestamp: new Date()
|
|
}]
|
|
});
|
|
return;
|
|
}
|
|
|
|
if (newPrefix.length > 5) {
|
|
await message.reply({
|
|
embeds: [{
|
|
color: 0x8aa2b3,
|
|
title: '',
|
|
author: {
|
|
name: message.author.username,
|
|
icon_url: message.author.displayAvatarURL(),
|
|
},
|
|
description: '<:no:1481811955592466492> prefix must be 5 characters or less!',
|
|
footer: {
|
|
text: `twitter @ ${message.guild.name}`,
|
|
icon_url: client.user.displayAvatarURL(),
|
|
},
|
|
timestamp: new Date()
|
|
}]
|
|
});
|
|
return;
|
|
}
|
|
|
|
const db = readDb();
|
|
db.prefixes = db.prefixes || {};
|
|
db.prefixes[message.guild.id] = newPrefix;
|
|
writeDb(db);
|
|
|
|
await message.reply({
|
|
embeds: [{
|
|
color: 0x8aa2b3,
|
|
title: '',
|
|
author: {
|
|
name: message.author.username,
|
|
icon_url: message.author.displayAvatarURL(),
|
|
},
|
|
description: `<:check:1481811973447356496> prefix for **${message.guild.name}** updated to \`${newPrefix}\`!`,
|
|
footer: {
|
|
text: `twitter @ ${message.guild.name}`,
|
|
icon_url: client.user.displayAvatarURL(),
|
|
},
|
|
timestamp: new Date()
|
|
}]
|
|
});
|
|
}
|
|
};
|
|
void time; |