【问题标题】:kickme discord.js command, kicks before can dmkickme discord.js 命令,在可以 dm 之前踢
【发布时间】:2021-06-03 10:08:06
【问题描述】:

我在获取命令以等待机器人在启动用户之前对用户进行 dm 处理时遇到了一些问题,我设置了等待 5 秒的功能,但它在 5 秒结束之前就启动了以下是我的代码和错误。

它说“等待”没有定义,但我看了here 并使用了其中一个,稍作修改。

我还有另一个不那么重要的问题,我将如何让运行 !kickme 命令的人登录到 .txt 文件或类似文件?

编辑:我认为 id 澄清。是的,我试图踢出发送 !kickme 命令的用户。它的本意是一个完全没用的命令,供人们乱用。它应该向他们发送带有服务器邀请的 dm(以便他们可以重新加入),然后踢他们。

到目前为止,它还没有向他们发送 dm,它只是在踢他们

const Discord = require('discord.js')


module.exports.run = async (bot, message, args) => {

    const user = message.author
    const member = message.guild.member(user);

    message.author.send(`Here is an invite so you can join back! https://discord.gg/FBXSduget2 `)
    
    const timew = async (bot, message, args) => {
        wait(5000);
        console.log("Waited 5s");
      
        wait(5000);
        console.log("Waited an additional 5s");
      };

      timew();
    
    if (member) {
        member
          .kick('User was kicked')
          .then(() => {
            console.log(`${user.tag} Kicked themself`);
            message.channel.send(`${user.tag} kicked themself`)
          })
          .catch(err => {
            message.reply('Unable');
            console.error(err);
          });
        }
    }

  module.exports.help = {
    name: "kickme"
  }

(node:13216) UnhandledPromiseRejectionWarning: ReferenceError: wait is not defined
    at timew (C:\Users\8fwbu\Desktop\CodeTProj\-Tux V2\commands\kickme.js:12:9)
    at Object.module.exports.run (C:\Users\8fwbu\Desktop\CodeTProj\-Tux V2\commands\kickme.js:19:7)
    at Client.<anonymous> (C:\Users\8fwbu\Desktop\CodeTProj\-Tux V2\main.js:42:31)
    at Client.emit (events.js:315:20)
    at MessageCreateAction.handle (C:\Users\8fwbu\node_modules\discord.js\src\client\actions\MessageCreate.js:31:14)
    at Object.module.exports [as MESSAGE_CREATE] (C:\Users\8fwbu\node_modules\discord.js\src\client\websocket\handlers\MESSAGE_CREATE.js:4:32)
    at WebSocketManager.handlePacket (C:\Users\8fwbu\node_modules\discord.js\src\client\websocket\WebSocketManager.js:384:31)
    at WebSocketShard.onPacket (C:\Users\8fwbu\node_modules\discord.js\src\client\websocket\WebSocketShard.js:444:22)
    at WebSocketShard.onMessage (C:\Users\8fwbu\node_modules\discord.js\src\client\websocket\WebSocketShard.js:301:10)
    at WebSocket.onMessage (C:\Users\8fwbu\node_modules\ws\lib\event-target.js:132:16)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:13216) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled 
with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)    
(node:13216) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
(node:13216) UnhandledPromiseRejectionWarning: DiscordAPIError: Cannot send messages to this user
    at RequestHandler.execute (C:\Users\8fwbu\node_modules\discord.js\src\rest\RequestHandler.js:154:13)
    at processTicksAndRejections (internal/process/task_queues.js:93:5)
    at async RequestHandler.push (C:\Users\8fwbu\node_modules\discord.js\src\rest\RequestHandler.js:39:14)
(node:13216) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled 
with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 2)    
Unicorn-Barf#9255 Kicked themself

【问题讨论】:

  • 好吧,问题正是它所说的,wait 似乎是一个您从未在任何地方定义过的函数。至于您的其他问题,您可以在发送的消息上使用.then() 并将用户踢到那里。
  • 另外,您似乎试图踢发送消息的人。也许不完全是你想做的。
  • 你可以使用message.guild.member(user)而不是message.member。

标签: javascript node.js discord discord.js


【解决方案1】:

您的错误来自使用 wait(5000);,因为它没有定义。

您可以在发送消息时使用await 以确保它们被发送。

await message.author.send(`Here is an invite`)
message.member.kick('they kicked themself')

【讨论】:

    猜你喜欢
    • 2021-06-01
    • 1970-01-01
    • 2021-11-13
    • 2020-11-18
    • 2020-10-20
    • 1970-01-01
    • 2021-06-12
    • 2021-08-04
    • 1970-01-01
    相关资源
    最近更新 更多