简体   繁体   English

我如何将其设置为异步函数

[英]How do i set this as an async function

I need to set this as an async function but im not sure how exacly, my first thought was to make it an async function in the Index.js by doing client.on('message', async message => { but even that doesnt work我需要将它设置为异步函数,但我不确定有多精确,我的第一个想法是通过执行client.on('message', async message => {但即使这样也没有工作

module.exports = {
    name: 'meme',
    description: 'sends a random meme',
    execute(async, message, args, ) {
        const Discord = require('discord.js');
        const { Random } = require("something-random-on-discord")
        const random = new Random();
        var oneLinerJoke = require('one-liner-joke');
        var getRandomJoke = oneLinerJoke.getRandomJoke({
          'exclude_tags': ['dirty', 'racist', 'marriage']
         
        });
        let data = await random.getMeme()
        message.channel.send(data)

  
}
}

You can indicate an async function by putting the async keyword to the definition like so:您可以通过将async关键字放在定义中来指示异步函数,如下所示:

async function execute(message, args) {
      const Discord = require('discord.js');
      const { Random } = require("something-random-on-discord")
      const random = new Random();
      var oneLinerJoke = require('one-liner-joke');
      var getRandomJoke = oneLinerJoke.getRandomJoke({
        'exclude_tags': ['dirty', 'racist', 'marriage']
      
      });
      let data = await random.getMeme()
      message.channel.send(data)
    }
    
    module.exports = {
      name: 'meme',
      description: 'sends a random meme',
      execute
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM