discord.js-commando宣布命令
我的announce.js命令有一些小问题 我已经尝试了一些不同的方法,但对突击队来说,我还是个新手 这是我目前拥有的discord.js-commando宣布命令,discord.js,Discord.js,我的announce.js命令有一些小问题 我已经尝试了一些不同的方法,但对突击队来说,我还是个新手 这是我目前拥有的 Announce.js const discord = require('discord.js'); const Commando = require('discord.js-commando'); module.exports = class AnnounceCommand extends Commando.Command { constructor(client) {
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);
}
};
现在它正在将公告发送到指定的频道,但是它有两个小问题
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
,如果有帮助的话。因此,在回到这个问题后,一段时间后,我可能会添加,我终于成功地以我最初想要的方式修复了它
以下是我的工作代码,供那些可能想自己尝试的人使用:
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);
}
};
const{Command}=require('discord.js commando');
const{MessageEmbed}=require('discord.js');
const config=require(“../../config.json”)
module.exports=类NewsCommand扩展命令{
建造商(客户){
超级(客户、{
名称:“宣布”,
别名:['ann'],
集团:'公会',
memberName:'宣布',
用户权限:['MANAGE_MESSAGES','MANAGE_CHANNELS'],
描述:“向指定频道发送公告”,
示例:[`${config.prefix}宣布[channel.提提][message]`,
args:[
{
关键字:“文本”,
提示:“您希望机器人宣布什么?”,
键入:“字符串”,
},
],
});
}
运行(消息){
if(message.author.bot)返回;
让text=message.content.split(“”);
设args=text.slice(1);
if(message.channel.type==“dm”)返回;
让channel=message.indications.channels.first();
如果(!通道)返回;
让announcement=args.slice(1.join)(“”);
let embed=new MessageEmbed()
.setAuthor(this.client.user.username,this.client.user.displayAvatarURL())
.set缩略图(this.client.user.displayAvatarURL())
.setColor(“随机”)
.addField(`Announcement`,Announcement,false)
.setFooter(this.client.user.username,this.client.user.displayAvatarURL())
.setTimestamp(新日期().toISOString())
返回通道。发送(嵌入);
}
};
因此,在回到这一点之后,一段时间之后,我可能会补充说,我终于设法以我最初想要的方式修复了它
以下是我的工作代码,供那些可能想自己尝试的人使用:
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);
}
};
const{Command}=require('discord.js commando');
const{MessageEmbed}=require('discord.js');
const config=require(“../../config.json”)
module.exports=类NewsCommand扩展命令{
建造商(客户){
超级(客户、{
名称:“宣布”,
别名:['ann'],
集团:'公会',
memberName:'宣布',
用户权限:['MANAGE_MESSAGES','MANAGE_CHANNELS'],
描述:“向指定频道发送公告”,
示例:[`${config.prefix}宣布[channel.提提][message]`,
args:[
{
关键字:“文本”,
提示:“您希望机器人宣布什么?”,
键入:“字符串”,
},
],
});
}
运行(消息){
if(message.author.bot)返回;
让text=message.content.split(“”);
设args=text.slice(1);
if(message.channel.type==“dm”)返回;
让channel=message.indications.channels.first();
如果(!通道)返回;
让announcement=args.slice(1.join)(“”);
let embed=new MessageEmbed()
.setAuthor(this.client.user.username,this.client.user.displayAvatarURL())
.set缩略图(this.client.user.displayAvatarURL())
.setColor(“随机”)
.addField(`Announcement`,Announcement,false)
.setFooter(this.client.user.username,this.client.user.displayAvatarURL())
.setTimestamp(新日期().toISOString())
返回通道。发送(嵌入);
}
};