【问题标题】:discord.js-commando Announce commanddiscord.js-commando 宣布命令
【发布时间】:2020-12-31 03:02:27
【问题描述】:

我的announce.js 命令有一些小问题。

我已经尝试了一些不同的东西,但对突击队来说通常是新手。

这是我目前拥有的。

Announce.js

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

module.exports = class AnnounceCommand extends Commando.Command {
  constructor(client) {
    super(client, {
      name: 'announce',
      aliases: ['ann'],
      group: 'moderation',
      memberName: 'announce',
      userPermissions: ['MANAGE_MESSAGES', 'MANAGE_CHANNELS'],
      description: 'Send an announcement to the specified channel',
      examples: ['announce Hello, world!'],
      args: [
        {
          key: 'text',
          prompt: 'What would you like the bot to announce?',
          type: 'string',
        },
      ],
    });
  }

  run(msg, { text }) {
    let channel = msg.mentions.channels.first();
    if (!channel) return;
    const embed = new discord.RichEmbed()
      .setAuthor(`Megumin`, `https://cdn.discordapp.com/avatars/735785909420556370/3db81cc7fb540907d7a147fb87118217.png?size=2048`)
      .setThumbnail(`https://cdn.discordapp.com/avatars/735785909420556370/3db81cc7fb540907d7a147fb87118217.png?size=2048`)
      .setColor(0xffcc00)
      .addField(`Announcement`, (text), false)
      .setFooter(`Megumin`, `https://cdn.discordapp.com/avatars/735785909420556370/3db81cc7fb540907d7a147fb87118217.png?size=2048`)
      .setTimestamp();
    return channel.send(embed);
  }
};

现在它正在向指定频道发送公告,但是它有两个小问题。

  1. 不会发送到公告频道
  2. 它在消息中提到了频道。

如果有人能向我解释我将如何解决这两个问题,我将不胜感激。

如果有帮助,这是我的index.js

const { Client } = require('discord.js-commando');
const path = require('path');
const {token, owner_id, prefix} = require("./config.json");

const client = new Client({
    commandPrefix: prefix,
    owner: owner_id,
    invite: 'https://discord.io/NewHorizonDevelopment',
})

client.registry
    .registerDefaultTypes()
    .registerGroups([
        ['misc', 'Misc'],
        ['moderation', 'Moderation'],
        ['fun', 'Fun']
    ])
    .registerDefaultGroups()
    .registerDefaultCommands()
    .registerCommandsIn(path.join(__dirname, 'commands'))

client.on('ready', () => {
    console.log(`Logged in as ${client.user.tag}(${client.user.id})`)
    client.user.setActivity(`${prefix}help`, {
        type: "STREAMING",
        url: "https://www.twitch.tv/discord"
    });
})

client.on('guildMemberAdd', (guildMember) => {
    guildMember.addRole(guildMember.guild.roles.find(role => role.name === "Member"));
});

client.on('error', console.error)


client.login(token)

如果有帮助,我正在使用 node.js 12.x 并使用 discord.js-commando

【问题讨论】:

    标签: discord.js


    【解决方案1】:

    所以在回到这个问题之后,我可能会在一段时间后添加,我终于设法按照我最初想要的方式修复它。

    这是我的工作代码,供那些可能想自己尝试的人使用:

    announce.js

    const { Command } = require('discord.js-commando');
    const { MessageEmbed } = require('discord.js');
    const config = require('../../config.json')
    
    module.exports = class NewsCommand extends Command {
        constructor(client) {
            super(client, {
                name: 'announce',
                aliases: ['ann'],
                group: 'guild',
                memberName: 'announce',
                userPermissions: ['MANAGE_MESSAGES', 'MANAGE_CHANNELS'],
                description: 'Send an announcement to the specified channel',
                examples: [`${config.prefix}announce [channel.mention] [message]`],
                args: [
                    {
                        key: 'text',
                        prompt: 'What would you like the bot to announce?',
                        type: 'string',
                    },
                ],
            });
        }
    
        run(message) {
            if (message.author.bot) return;
    
            let text = message.content.split(" ");
            let args = text.slice(1);
    
            if (message.channel.type === "dm") return;
    
            let channel = message.mentions.channels.first();
            if (!channel) return;
            
            let announcement = args.slice(1).join(" ");
    
            let embed = new MessageEmbed()
                .setAuthor(this.client.user.username, this.client.user.displayAvatarURL())
                .setThumbnail(this.client.user.displayAvatarURL())
                .setColor('RANDOM')
                .addField(`Announcement`, announcement, false)
                .setFooter(this.client.user.username, this.client.user.displayAvatarURL())
                .setTimestamp(new Date().toISOString())
            return channel.send(embed);
        }
    };
    

    【讨论】:

      猜你喜欢
      • 2020-01-14
      • 2019-08-21
      • 1970-01-01
      • 2021-08-10
      • 2021-01-13
      • 2020-09-09
      • 1970-01-01
      • 2020-04-13
      • 1970-01-01
      相关资源
      最近更新 更多