【问题标题】:Trying to count up with discord bot试图用不和谐机器人数数
【发布时间】:2020-07-08 07:19:18
【问题描述】:

我对此很陌生。大约 10 到 15 年前,我涉足 javascript,但它只是编辑现有文件。我一直在搜索,但找不到有关如何执行此操作的权威指南。我正在尝试发出命令,并让机器人数数。这是我几乎所有的代码。

const Discord = require('discord.js');

const client = new Discord.Client();

client.once('ready', () => {
    console.log('Ready!');
});

client.on('message', message => {
    if (message.content === `!test`) {
        async def cmd_thatcommand(self,channel):
        await self.safe_send_message(channel, "+1")
        counter += 1
        return Response('command used {} times'.format(counter))
    } else if (message.content === `!beep`) {
        message.channel.send('Boop.');
    } else if (message.content === `!server`) {
        message.channel.send(`Server name: ${message.guild.name}\nTotal members: ${message.guild.memberCount}`);
    } else if (message.content === `!user-info`) {
        message.channel.send(`Your username: ${message.author.username}\nYour ID: ${message.author.id}`);
    }
});

我尝试了我在网上找到的几行代码(例如 bot counting command discord ),但它们总是抛出某种错误。它为上述代码提供的一个是:

                async def cmd_thatcommand(self,channel):
                      ^^^

SyntaxError: Unexpected identifier
[90m    at wrapSafe (internal/modules/cjs/loader.js:1054:16)[39m
[90m    at Module._compile (internal/modules/cjs/loader.js:1102:27)[39m
[90m    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1158:10)[39m
[90m    at Module.load (internal/modules/cjs/loader.js:986:32)[39m
[90m    at Function.Module._load (internal/modules/cjs/loader.js:879:14)[39m
[90m    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12)[39m
[90m    at internal/main/run_main_module.js:17:47[39m

我为此找到的指南使用 Node 和 ESLint(如果有帮助的话)。

【问题讨论】:

  • 请添加您所面临的确切错误消息,并可能包含指向您正在关注的指南的链接
  • 抱歉耽搁了。我尝试的第一个部分来自这个线程,但我认为没有足够的代码让它工作。 stackoverflow.com/questions/41675454/…
  • 对垃圾邮件感到抱歉。编辑了原始帖子。

标签: discord


【解决方案1】:

def 在 Java Script 中不是一个东西。如果 def 尝试使用函数代替。如果使用“:”,您也必须使用“{}”。

function example(){
     console.log("This is how you make a function in Java Script");

} https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function

【讨论】:

    猜你喜欢
    • 2021-07-13
    • 2018-03-20
    • 2017-05-31
    • 2021-09-04
    • 2020-07-03
    • 2020-09-23
    • 2021-10-30
    • 2021-08-05
    • 2021-05-27
    相关资源
    最近更新 更多