不和机器人不响应



我正在使用这个代码,但我的Discord bot是离线的,没有响应。我已经给了它所需的权限,但它仍然没有响应。

你能看一下吗?出于隐私原因,我已经删除了令牌,但我显然在运行文件时使用它们,所以请查看代码并让我知道如何使此工作?

const NLPCloudClient = require('nlpcloud');
const { Client, GatewayIntentBits } = require('discord.js');
// Load NLP Cloud token and Discord Bot token.
const nlpcloudToken = '';
if (nlpcloudToken == null) {
console.error('No NLP Cloud token received');
process.exit();
}
const discordBotToken = '';
if (discordBotToken == null) {
console.error('No Discord bot token received');
process.exit();
}
// Initialize the NLP Cloud and Discord clients.
const nlpCloudClient = new NLPCloudClient('fast-gpt-j', nlpcloudToken, true)
const discordClient = new Client({ intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages, GatewayIntentBits.MessageContent, GatewayIntentBits.GuildMembers] });
let history = [];
discordClient.on("messageCreate", function(message) {
if (message.author.bot) return;
(async () => {
// Send request to NLP Cloud.
const response = await nlpCloudClient.chatbot(`${message.content}`, history);
// Send response to Discord bot.
message.reply(`${response.data['response']}`);
// Add the request and response to the chat history.
history.push({'input':`${message.content}`,'response':`${response.data['response']}`});

})();
});
非常感谢你的帮助。我试过给它所有的权限,并把它添加到服务器。

在您的代码中,您只检查是否提供了Discord令牌,但您忘记使用令牌登录。在这种情况下,您还必须添加这行代码:

discordClient.login(discordBotToken)

这将为bot建立一个与Discord API端点的连接。连接成功后,令牌已被Discord验证,机器人将出现在线,您将能够使用事件。

在这一行中,您正在检查是否在discordBotToken变量中提供了令牌,因此如果提供了令牌,则必须使用else使bot登录,如下所示:

const NLPCloudClient = require('nlpcloud');
const { Client, GatewayIntentBits } = require('discord.js');
// Load NLP Cloud token and Discord Bot token.
const nlpcloudToken = '';
if (nlpcloudToken == null) {
console.error('No NLP Cloud token received');
process.exit();
}
// Initialize the NLP Cloud and Discord clients.
const nlpCloudClient = new NLPCloudClient('fast-gpt-j', nlpcloudToken, true)
const discordClient = new Client({ intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages, GatewayIntentBits.MessageContent, GatewayIntentBits.GuildMembers] });
// Set Discord token and check if provided, then login
const discordBotToken = '';
if (discordBotToken == null) {
console.error('No Discord bot token received');
process.exit();
} else {
discordClient.login(discordBotToken);
}
let history = [];
discordClient.on("debug", console.debug); // For debugging Discord endpoint purposes only
discordClient.once("ready", () => console.log(`Signed in as ${discordClient.user.tag}`));
discordClient.on("messageCreate", function(message) {
if (message.author.bot) return;
(async () => {
// Send request to NLP Cloud.
const response = await nlpCloudClient.chatbot(`${message.content}`, history);
// Send response to Discord bot.
message.reply(`${response.data['response']}`);
// Add the request and response to the chat history.
history.push({'input':`${message.content}`,'response':`${response.data['response']}`});

})();
});

最新更新