简体   繁体   English

我在 discord.js-commando 中发出了一个命令来宣布我的机器人所在的所有频道。但我收到了一个错误

[英]I made a command in discord.js-commando to anounce all the channels my bot is in. but I got an error

const Commando = require('discord.js-commando');

module.exports = class AnnounceCommand extends Commando.Command {
    constructor(client) {
        super(client, {
            name: 'announce',
            aliases: ['an'],
            group: 'util',
            memberName: 'announce',
            description: 'Announce something to the topmost channel in all servers the bot is in.',
            details: 'Only the bot owner may use this command.',
            examples: ['announce Hello, world!'],
            args: [
                {
                    key: 'msg',
                    label: 'message',
                    prompt: 'What should be announced?',
                    type: 'string'
                }
            ],
            guarded: true,
        });
    }

    hasPermission(msg) {
        return this.client.isOwner(msg.author);
    }

    async run(msg, args) {
        this.client.guilds.array().forEach((guild) => {
            let channels = guild.channels.filter((channel) => {
                return channel.type === 'text' && channel.permissionsFor(guild.me).has(['VIEW_CHANNEL', 'SEND_MESSAGES']);
            });
            if (channels.array().length > 0) {
                channels = channels.sort((a, b) => {
                    return a.calculatedPosition - b.calculatedPosition;
                }).array();
                channels[0].send(args.msg).catch(e => console.error(e));
            }
        });
    }
};

but in console I got:但在控制台我得到:

TypeError: this.client.guilds.array is not a function at AnnounceCommand.run (/home/runner/emperor-2/commands/util/announce.js:30:22)类型错误:this.client.guilds.array 不是announceCommand.run 中的函数(/home/runner/emperor-2/commands/util/announce.js:30:22)

The property guilds that is a GuildManager Class has no array() method.作为 GuildManager 类的属性 guilds 没有 array() 方法。 The correct line code should be this.client.guilds.cache.forEach() .正确的行代码应该是this.client.guilds.cache.forEach()

I suggest you to read the documentation: Class GuildManager我建议你阅读文档: Class GuildManager

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

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