【问题标题】:Problem with Prefix in Discord.js (including .toUpperCase())Discord.js 中的前缀问题(包括 .toUpperCase())
【发布时间】:2020-07-02 05:07:50
【问题描述】:

基本上,我已经使用 discord.js 库开发了一个机器人好几个星期了,最近遇到了一个小而关键的问题。本质上,当我声明我的论点时,我也这样做了,以便使用 .toUpperCase() 将消息内容 (message.content) 大写。基本上这样做,无论您输入的前缀类型如何(符号方面),程序都会将其全部读取为有效。

仅举例:!help - 应该可以,但是如果我输入 .help,它也会被读取为有效。

无论如何,这里是代码。感谢所有帮助!

bot.on('message', message =>{
    let args = message.content.toUpperCase().substring(PREFIX.length).split(" ");
    const sender = message.member;

    switch(args[0])
    {
    case 'HELP':
            message.reply("I've sent you some documentation on all the commands that you can use...").then(d_msg => {d_msg.delete(3000); });
            message.delete(3000);
            const attachment = new Attachment('./UtilityBot_Documentation.txt') 
            message.author.send('[Education] Bot - Documentation');
            message.author.send(attachment);
            break;
    }
})

【问题讨论】:

  • 有什么问题?

标签: api bots discord discord.js


【解决方案1】:

discord.js 教程涵盖了与您正在尝试做的事情极为相似的问题。我建议你检查一下。我具体链接的页面与您做了非常相似的事情,但如果您还没有这样做,那么值得一读整个内容。一般来说,我会在您建立 args 的位置上方添加以下行。

如果 (!message.content.startsWith(PREFIX)) 返回;

我在这里所做的是,如果消息不以前缀开头,则停止运行,直到发送新消息。我可能会遗漏一些东西,但一定要查看教程。写的真好。

https://discordjs.guide/creating-your-bot/commands-with-user-input.html#basic-arguments

【讨论】:

    猜你喜欢
    • 2021-09-26
    • 2021-11-13
    • 2020-12-26
    • 2020-06-24
    • 1970-01-01
    • 2021-04-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多