【问题标题】:Discord.JS Ping Edit CommandDiscord.JS Ping 编辑命令
【发布时间】:2020-04-29 02:39:37
【问题描述】:

好吧,基本上,我正在尝试在作者发送 !ping 的位置发出命令,机器人用 Pinging 响应,然后将其编辑为 Pong 转到下一行,然后说明响应需要多少毫秒。现在的问题是,当我 const 将要发送的消息并对其进行编辑时,当我将 await 添加到 const 时,它说编辑该变量不是一个函数,它说仅适用于 async

【问题讨论】:

  • 您好,欢迎来到 StackOverflow。请不要使用图片向我们展示您的代码。 StackOverflow 编辑器有很好的工具来显示你的代码,请使用它们:)
  • send 返回一个promise,你需要要么使用.then回调,要么使用async/await语法

标签: discord.js


【解决方案1】:

你来了,芽:

client.on('messageUpdate', (oldMessage, newMessage) => {

    if (oldMessage.content === 'Pinging...') {

        var oldMessageTimestamp = oldMessage.createdTimestamp;
        var newMessageTimestamp = newMessage.editedTimestamp;

        newMessage.edit(`Pong!\nPonged back the ping in ${Math.floor(newMessageTimestamp - oldMessageTimestamp)} milliseconds!`);
    }
});

client.on('message', message => {

    if (message.content === `${prefix}` + `ping`) {

        message.channel.send('Pinging...').then(message => {

            message.edit('Pong!\nPonged back the ping in milliseconds!');
        })
    }
});

我相信您的错误在于几件事,一是您试图编辑常量变量,二是您试图对变量使用 .edit 方法,不仅如此,您还试图在创建时进行数学运算日期而不是根本不起作用的创建时间戳,您必须查看创建时间戳和编辑时间戳之间的时间。

【讨论】:

    猜你喜欢
    • 2020-12-04
    • 1970-01-01
    • 1970-01-01
    • 2023-01-29
    • 2021-10-11
    • 2021-07-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多