Discord. js проблема TypeError: Discord.bot не является конструктором - PullRequest
0 голосов
/ 09 мая 2020

Итак, я кодирую бота Discord и получаю сообщение об ошибке, которое выглядит примерно так:

TypeError: Discord.bot is not a constructor

Вот мой код.

const Discord = require('discord.js');
const bot = new Discord.bot();

const token = 'TOKEN';

const PREFIX = '!';

const ytdl = require("ytdl-core");

var version = '1.0.1'

var servers = {};

bot.on('ready', () => {
    console.log('This bot is online!')
    bot.user.setActivity('SouthAir Servers', {
        type: 'WATCHING'
    }).catch;
})


bot.on('message', message => {

    let args = message.content.substring(PREFIX.length).split(" ");

    switch (args[0]) {
        case 'clear':
            if (!args[1]) return message.reply('Error, please define a specific number of messages you want to clear.')
            message.channel.bulkDelete(args[1]);
            break;


        case 'strike':
            if (!args[1]) message.channel.send('You need to specify a user to strike!')

            const user = message.mentions.users.first();

            if (user) {
                const member = message.guild.member(user);

                if (member) {
                    message.channel.send(`${user} has been striked. Any more might result in a demotion!`)
                        .catch(err => {
                            message.reply('Failed to strike user.');
                        });
                } else {
                    message.reply("That user is not in this server!")
                }
            } else {
                message.reply('That user is not in this server.')

            }
            break;

        case 'cmds':

            message.channel.send('Command List: \n !strike - Strikes a user. \n !clear - Removes a certain amount of messages. \n !lock - Locks down a channel so that only one person can talk. \n !info - The bot will DM you info about SouthAir and itself.');

            break;


        case 'commands':

            message.channel.send('Command List: \n !strike - Strikes a user. \n !clear - Removes a certain amount of messages. \n !lock - Locks down a channel so that only one person can talk. \n !info - The bot will DM you info about SouthAir and itself.');

            break;


        case 'info':
            message.author.send('Venstres is the creator of SouthAir. \n The Roblox Group link is: https://www.roblox.com/groups/4073893/SouthAir#!/about . \n SouthAir is a Roblox roleplay game that makes flying in a Roblox airplane fun. \n More info coming soon. \n Bot created by Inki/DevOffline. (Version: 1.0.1)')
            break;

            const ms = require("ms");
            const args = message.content.slice(settings.PREFIX.length).trim().split(/ +/g);
            const command = args.shift().toLowerCase();

            if (command === "ban") {

                bot.moderator.ban(message.guild.members.get(mentions.users.first().id), {
                    time: ms(args[1]),
                    reason: args.slice(2).join(" "),
                    author: message.member
                }).then((banData) => {
                    console.log(banData);
                });
                break;

                if (command === "unban") {

                    bot.moderator.unban(args[0], {
                        reason: args.slice(1).join(" "),
                        author: message.member
                    }).then((banData) => {
                        console.log(banData);
                    });
                    break;


                }
            }
    }
});


const ticketsystem = require("djs-ticketsystem");

bot.on("message", async message => {
    if (message.content == '-new') {

        ticketsystem.createTicket({
            name: 'new-ticket',
            category: 'TICKETS',
            owner: message.author,
            roles: [
                'Owner',
                'Support'
            ],
            openmessage: 'Creating your ticket...',
            ticketmessage: 'Thank-you for creating a ticket!',
            messagelinker: message
        }).catch(err => {
            message.reply('Failed to create a new ticket.')
        });

    }
});

bot.on("message", (message) => {

    const ms = require("ms"); // npm install ms
    const args = message.content.slice(settings.prefix.length).trim().split(/ +/g);
    const command = args.shift().toLowerCase();

    if (command === "mute") {
        // /mute @Rakox 2d bad words
        // will mute Rakox for 2 days and the reason will be "bad words"

        bot.moderator.mute(message.guild.members.get(mentions.users.first().id), {
            time: ms(args[1]),
            reason: args.slice(2).join(" "),
            author: message.member,
            mutedRoleID: "689384052142243929"
        }).then((muteData) => {
            console.log(muteData); // {...} (id, type, author, reason and more)
        });
        // And the member has been muted!
    }
});

bot.on("message", (message) => {

    const ms = require("ms"); // npm install ms
    const args = message.content.slice(settings.prefix.length).trim().split(/ +/g);
    const command = args.shift().toLowerCase();

    if (command === "unmute") {
        // /unmute @Rakox i'm nice
        // will un-mute Rakox and the reason will be "i'm nice"

        bot.moderator.unmute(message.guild.members.get(mentions.users.first().id), {
            reason: args.slice(1).join(" "),
            author: message.member,
            mutedRoleID: "689384052142243929"
        }).then((muteData) => {
            console.log(muteData); // {...} (id, type, author, reason and more)
        });
        // And the member has been un-muted!
    }
});

bot.on("message", (message) => {

    const ms = require("ms"); // npm install ms
    const args = message.content.slice(settings.prefix.length).trim().split(/ +/g);
    const command = args.shift().toLowerCase();

    if (command == "kick") {
        // /kick @Rakox flood
        // will kick Rakox for "flood"

        bot.moderator.kick(message.guild.members.get(mentions.users.first().id), {
            reason: args.slice(1).join(" "),
            author: message.member
        }).then((kickData) => {
            console.log(kickData); // {...} (id, type, author, reason and more)
        });
        // And the member has been kicked!
    }
});

bot.on("message", (message) => {

    const ms = require("ms"); // npm install ms
    const args = message.content.slice(settings.prefix.length).trim().split(/ +/g);
    const command = args.shift().toLowerCase();

    if (command == "warn") {
        // /warn @Rakox spam
        // will warn Rakox for "spam"

        bot.moderator.warn(message.guild.members.get(mentions.users.first().id), {
            reason: args.slice(1).join(" "),
            author: message.member
        }).then((warnData) => {
            console.log(warnData); // {...} (id, type, author, reason and more)
        });
        // And the member has been warned!
    }
});

bot.login(token);

1 Ответ

0 голосов
/ 09 мая 2020

Вы должны заменить Discord.bot() на Discord.client(), так как Discord.bot()

не существует
...