我正在开发一个不和谐的机器人,但我一直收到这个错误

时间:2021-04-07 10:52:57

标签: node.js discord bots token

This is the error i get, it says syntaxerror: unexpected token '.'

这是我使用的代码,有人知道这里有什么问题吗?我对编码很陌生,我将一个机器人改造成一个具有新功能的新机器人,我和朋友一起做这件事。如果有人能帮我找到这个错误,我很乐意,我一直在寻找很多时间,但我找不到任何对我来说似乎可疑的东西,所以如果你们找到了一些东西,那就太好了。谢谢

const Discord = require('discord.js');
const {Client, Attachment, MessageEmbed} = require('discord.js');
const bot = new Discord.Client();
const fs = require('fs');
const { prefix, token } = require('./Storages/config.json');

bot.commands = new Discord.Collection();
const commandFiles = fs.readdirSync('./Commands/').filter(file => file.endsWith('.js'));
for(const file of commandFiles){
    const command = require(`./Commands/${file}`);
    bot.commands.set(command.name, command);
}


bot.on('ready', () =>{
    console.log(`Logged in as ${bot.user.tag}`)
    bot.user.setPresence({
        status: 'online',
        activity: {
            name: 'h!help | Made by cxntered',
            type: 'PLAYING',
        }
    })
})

setInterval(function presenceReset() {
    bot.user.setPresence({
        status: 'online',
        activity: {
            name: 'h!help | Made by cxntered',
            type: 'PLAYING',
        }
    })
}, 86400000)

bot.on('guildCreate', guild => {
    const channel = guild.channels.cache.find(channel => channel.type === 'text' && channel.permissionsFor(guild.me).has('SEND_MESSAGES'))
    channel.send("**Thank you for adding me!** \n`-` My prefix is `h!` \n`-` You can see all commands by typing `h!help` \n`-` Join the HyDiscord server! `h!invite`")
})

bot.on('message', message => {
    if (!message.content.startsWith(prefix) || message.author.bot) return;

    const args = message.content.slice(prefix.length).trim().split(/ +/);
    const commandName = args.shift().toLowerCase();

    const command = bot.commands.get(commandName)
        || bot.commands.find(cmd => cmd.aliases && cmd.aliases.includes(commandName));

    if (!command) return;

    if (command.guildOnly && message.channel.type === 'dm') {
        return message.reply('I can\'t execute that command inside DMs!');
    }

    try {
        command.execute(message, args, bot);
    } catch (error) {
        console.error(error);
        message.channel.send('There was an error trying to execute that command!');
    }
});

bot.login(token);

0 个答案:

没有答案