gpt4 book ai didi

javascript - ROBLOX Discord 机器人

转载 作者:行者123 更新时间:2023-12-02 21:22:22 24 4
gpt4 key购买 nike

我正在尝试创建一个连接到我创建的 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 错误:错误:Shout 失败,验证登录、权限和消息

最佳答案

首先,您不会关闭 client.on('ready') 状态。

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

这个函数永远不会回复,因为你在回复之前使用了 return。

您的 groupId 看起来像 未定义,因为您声明了它 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);

关于javascript - ROBLOX Discord 机器人,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60813045/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com