ROBLOX Discord бот - PullRequest
       12

ROBLOX Discord бот

0 голосов
/ 23 марта 2020

Я пытаюсь создать диссон-бота, который подключается к моей учетной записи Roblox. Я пытаюсь создать команду, которая будет выводить сообщение в группе, но при входе в систему возникает проблема, и я не могу понять, как ее решить.

let roblox = require('noblox.js');
const { Client } = require("discord.js");
const { config } = require("dotenv");

const client = new Client({
    disableEveryone: true
});

config({
    path: __dirname + "/.env"
});

let prefix = process.env.PREFIX
let groupId = groupid;

client.on("ready", () => {
    console.log("I'm Ready!");

function login() {
    roblox.cookieLogin(process.env.COOKIE)
}

login()
    .then(function () {
        console.log(`Logged in to ${username}`);
    })
    .catch(function (error) {
        console.log(`Login error: ${error}`);
    });

client.on("message", async message => {
    console.log(`${message.author.username} said: ${message.content}`);
    if (message.author.bot) return;
    if (message.content.indexOf(prefix) !== 0) return;

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

    if (command === "shout") {
        if (!args) { 
            return;
            message.reply("You didn't specify a message to shout.")
        }
        const shoutMSG = args.join(" "); 

        roblox.shout(groupId, shoutMSG)
            .then(function() {
                console.log(`Shouted ${shoutMSG}`); 
            })
            .catch(function(error) { 
                console.log(`Shout error: ${error}`)
            });
    }
})

client.login(process.env.TOKEN);

Это дает мне ошибка: Shout error: Error: Shout failed, verify login, permissions, and message

1 Ответ

1 голос
/ 23 марта 2020

В первый раз вы не закрываете client.on('ready') состояние.

        if (!args) { 
            return;
            message.reply("You didn't specify a message to shout.")
        }

Эта функция никогда не ответит, потому что вы используете return перед ответом.

Ваш идентификатор группы выглядит как undefined, потому что вы объявляете его let groupId = groupid;, так что это один Кстати, почему вы получили эту ошибку.

let roblox = require('noblox.js');
const { Client } = require("discord.js");
const { config } = require("dotenv");

const client = new Client({
    disableEveryone: true
});

config({
    path: __dirname + "/.env"
});

let prefix = process.env.PREFIX
let groupId = groupid;

client.on("ready", () => {
    console.log("I'm Ready!");
})

function login() {
    roblox.cookieLogin(process.env.COOKIE)
}

login()
    .then(function () {
        console.log(`Logged in to ${username}`);
    })
    .catch(function (error) {
        console.log(`Login error: ${error}`);
    });

client.on("message", async message => {
    console.log(`${message.author.username} said: ${message.content}`);
    if (message.author.bot) return;
    if (message.content.indexOf(prefix) !== 0) return;

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

    if (command === "shout") {
        if (!args) return message.reply("You didn't specify a message to shout.")
        const shoutMSG = args.join(" "); 
        roblox.shout(groupId, shoutMSG)
            .then(function() {
                console.log(`Shouted ${shoutMSG}`); 
            })
            .catch(function(error) { 
                console.log(`Shout error: ${error}`)
            });
    }
})

client.login(process.env.TOKEN);
...