为什么我的Discord命令没有响应,尽管在线并且没有检测到错误?

贾坎兹

我是JavaScript的初学者,但是之前我已经用C#编写了一个项目。对不起,如果我犯了菜鸟错误!

我最近开始为碰巧要管理的服务器编写Discord机器人代码,并创建了一个频道,在该频道中,垃圾邮件在垃圾邮件聊天中标记了用户。对于我的一生,只有一个小问题无法解决。我发出的命令无效,而且我不确定代码在哪里出错。VS Code也不检测任何错误。该代码在我的笔记本电脑上本地托管。

我一直在关注CodeLyon的教程,并且它们的代码效果很好。我不确定为什么我的代码无法工作,尽管它遵循类似的格式和通用代码。

我一无所获,无法通过搜索查询进行研究。多种解决方案均无效,包括一个解决方案,其中我console.log在终端上的一行中放置一行,以指示该僵尸程序检测到我发送的消息中的前缀。该解决方案不起作用,所以我迷路了。我的所有代码看起来都是可运行的,并且很明显,该机器人可以在线发送,因为它可以在特定频道中发送垃圾邮件。是否有更新更改了discord.js检测消息的方式?

这是index.js代码(谢天谢地只有46行),第二段代码是临近末尾的if语句所期望的test.js文件

const Discord = require('discord.js');
const client = new Discord.Client();
const commandPrefix = 'j!';
const fs = require('fs');
const commandFiles = fs.readdirSync('./commands/').filter(file => file.endsWith('.js'));
 
// (client.login token would go here, but removed for censorship's sake)
client.on('ready', () => {
    console.log('"jaka-bot!!~" is now online!');
 
    var spamChannel = client.channels.cache.get('(are channel tags meant to be censored?)');
    setInterval(() => {
        spamChannel.send("||(user id removed for censorship)|| Hi there! I'm **jaka-bot**, a bot made by jakanz! ( Or as you may know them as *'jaka-chan'* or simply *'jaka.'* )\n\n**Make sure to DM jaka-chan if these messages ever stop!** It means that his code must've stopped due to lost internet connection or his laptop crapped out.");
    }, 1)
})
 
client.commands = new Discord.Collection();
for(const file of commandFiles){
    const command = require(`./commands/${file}`);
    client.commands.set(command.name, command);
}
 
// bot cmds
client.on('message', message => {
    // if the message content does not start with the prefix or the message author is the bot, ignore
    if(!message.content.startsWith(commandPrefix) || message.author.bot) return;
 
    // variables for cmds
    const args = message.content.slice(commandPrefix.Length).split("/ +/");
    const command = args.shift().toLowerCase();
 
    // socials
    if(command == "test"){
        client.commands.get("test").execute(message, args);
    }
})
module.exports = {
    name: 'test',
    description: "test",
    execute(message, args){
        message.channel.send("test test test");
    }
}

(我提供了所有可能的代码,因为即使问题出在另一个问题上,我也不想给出随机的代码块。)

所有代码看起来都是可以接受的,但是我不确定代码将从哪里删除,这将使bot对我的命令无响应!如果您能提供帮助,将不胜感激。祝你今天愉快!

sup39

要获取字符串的长度,请使用.length代替.Length

const args = message.content.slice(commandPrefix.Length).split("/ +/");

应该

const args = message.content.slice(commandPrefix.length).split("/ +/");

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章