const Discord = require('discord.js')
const fs = require('fs')
const client = new Discord.Client()
const config = require('./config.json')
const fetch = require('node-fetch')
client.commands = new Discord.Collection()
fs.readdir('./commands', (err, files) => {
if (err) console.log(err)
let jsfile = files.filter(f => f.split('.').pop() === 'js')
if (jsfile.length <= 0) return message.channel.send("Команды не найдены!")
console.log(`Загружено ${jsfile.length} команд`)
jsfile.forEach((f, i) => {
let props = require(`./commands/${f}`)
client.commands.set(props.help.name, props)
})
})
client.on('ready', () => {
console.log(`Бот ${client.user.username} запустился`);
client.user.setPresence({
status: 'online',
activity: {
type: 'STREAMING',
name: 'YouTube',
}
})
})
client.on('message', message => {
let prefix = config.prefix
let guildPrefix = prefix.getPrefix(message.guild.id);
if (!guildPrefix) guildPrefix = prefix;
if (!message.content.startsWith(prefix) || message.author.bot) return;
let messageArray = message.content.split(' ')
let command = messageArray[0]
let args = messageArray.slice(1)
let command_file = client.commands.get(command.slice(prefix.length))
if (command_file) command_file.run(client, message, args, prefix)
})
client.login(config.token)
// вверху со всеми импортами
let fs = require("fs")
let prefixes = require("./prefixes.json")
// ниже
let sid = message.guild.id
if(!prefixes[sid]){
prefixes[sid] ={
prefix:"любой префикс по умолчанию",
};
};
let prefix = prefixes[sid].prefix
fs.writeFile("./prefixes.json",JSON.stringify(prefixes),(err)=>{
if (err) console.log(err)
}
// вверху со всеми импортами
let fs = require("fs")
let prefixes = require("./prefixes.json")
// ниже
let sid = message.guild.id
prefixes[sid] ={
prefix:args[0]
}
fs.writeFile("./prefixes.json",JSON.stringify(prefixes),(err)=>{
if (err) console.log(err)
}
let prefix = '!';
let currencySymbol = '@';
discordBot.on('message', (msg) => {
let [ command, ...args ] = msg.content.split(' ');
switch(true) {
case(command === `{ $prefix }set-prefix`):
prefix = args[0] ?? prefix;
break;
case(command === `{ $prefix }set-currency`):
currencySymbol = args[0] ?? currencySymbol;
break;
default: break;
};
});