0

我试图让我们的宣布命令工作,但它不断抛出以下错误:

@Nimbi, An error occurred while running the command: ReferenceError: stopTyping is not defined
You shouldn't ever receive an error like this.
Please contact Nimbi#4961.

这是我的announce.js代码:

const stripIndents = require('common-tags').stripIndents;
const { Command } = require('discord.js-commando');
require('dotenv').config();

ANNOUNCE_CHANNEL_NAME = process.env.ANNOUNCEMENT_CHANNEL;
NEWS_CHANNEL_NAME = process.env.NEWS_CHANNEL;
MODLOG_CHANNEL_NAME = process.env.MODLOG_CHANNEL;

module.exports = class NewsCommand extends Command {
    constructor (client) {
      super(client, {
        name: 'announce',
        memberName: 'announce',
        group: 'mod',
        aliases: ['news', 'ann', 'a'],
        description: 'Make an announcement in the news channel',
        format: 'Announcement',
        examples: ['announce John Appleseed reads the news'],
        guildOnly: true,
        throttling: {
          usages: 2,
          duration: 3
        },
        args: [
          {
            key: 'body',
            prompt: 'What do you want me to announce?',
            type: 'string'
          }
        ],
        userPermissions: ['MANAGE_MESSAGES'],
        clientPermissions: ['MANAGE_MESSAGES']
      });
    }
  
    run (msg, {body}) {
      try {
        startTyping(msg);
  
        let announce = body,
          newsChannel = null;
  
        const announceEmbed = new MessageEmbed(),
          modlogChannel = msg.guild.settings.get('modLogChannel',
            msg.guild.channels.find(c => c.name === MODLOG_CHANNEL) ? msg.guild.channels.find(c => c.name === MODLOG_CHANNEL).id : null);
  
        if (msg.guild.settings.get('announcechannel')) {
          newsChannel = msg.guild.channels.find(c => c.id === msg.guild.settings.get('announcechannel'));
        } else {
          msg.guild.channels.find(c => c.name === 'announcements')
            ? newsChannel = msg.guild.channels.find(c => c.name === ANNOUNCEMENT_CHANNEL)
            : newsChannel = msg.guild.channels.find(c => c.name === NEWS_CHANNEL);
        }
  
        if (!newsChannel) throw new Error('nochannel');
        if (!newsChannel.permissionsFor(msg.guild.me).has(['SEND_MESSAGES', 'VIEW_CHANNEL'])) throw new Error('noperms');
  
        newsChannel.startTyping(1);
  
        announce.slice(0, 4) !== 'http' ? announce = `${body.slice(0, 1).toUpperCase()}${body.slice(1)}` : null;
        msg.attachments.first() && msg.attachments.first().url ? announce += `\n${msg.attachments.first().url}` : null;
  
        announceEmbed
          .setColor('#AAEFE6')
          .setAuthor(msg.author.tag, msg.author.displayAvatarURL())
          .setDescription(stripIndents`**Action:** Made an announcement`)
          .setTimestamp();
  
        newsChannel.msg.say(announce);
        newsChannel.stopTyping(true);
  
        if (msg.guild.settings.get('mod-logs', true)) {
          if (!msg.guild.settings.get('hasSentModLogMessage', false)) {
            msg.reply(oneLine` I can keep a log of moderator actions if you create a channel named **${MODLOG_CHANNEL_NAME}**
                          (or some other name configured by the ${msg.guild.commandPrefix}setmodlogs command) and give me access to it.
                          This message will only show up this one time and never again after this so if you desire to set up mod logs make sure to do so now.`);
            msg.guild.settings.set('hasSentModLogMessage', true);
          }
          modlogChannel && msg.guild.settings.get('mod-logs', false) ? msg.guild.channels.get(modlogChannel).msg.say('', {embed: announceEmbed}) : null;
        }
  
        stopTyping(msg);
  
        return msg.embed(announceEmbed);
  
      } catch (err) {
        stopTyping(msg);
  
        if ((/(?:nochannel)/i).test(err.toString())) {
          return msg.reply(`there is no channel for me to make the announcement in. Create channel named either ${ANNOUNCE_CHANNEL_NAME} or ${NEWS_CHANNEL_NAME}`);
        } else if ((/(?:noperms)/i).test(err.toString())) {
          return msg.reply(`I do not have permission to send messages to the ${ANNOUNCE_CHANNEL_NAME} or ${NEWS_CHANNEL_NAME} channel. Better go fix that!`);
        }
  
  
        return msg.reply(oneLine`An error occurred but I notified ${this.client.owners[0].username}
        Want to know more about the error? Join the support server by getting an invite by using the \`${msg.guild.commandPrefix}invite\` command `);
      }
    }
};

我的discord.js版本是:^12.5.1

我的discord.js-commando版本是:^0.11.1

我的node.js版本是:^12.0.0

我已经尝试使用以下方法定义它:

const {startTyping, stopTypeing } = require('discord.js');

const {startTyping, stopTypeing } = require('util');

但是,两者都只是抛出了startTyping is not a function错误。

任何帮助将非常感激。

4

1 回答 1

1

注意:这是在 discord.js@13 及以后

开始打字

// like 101arrowz said, startTyping (or now sendTyping) is a method of the TextChannel, which you can get by msg.channel
message.channel.sendTyping()

Discord.js 和 commando(由同一个人开发)效果很好,但如果您有任何问题,我建议您阅读文档或在他们的 discord 服务器上询问(他们确实有帮助)

于 2021-08-12T17:40:20.017 回答