我正在创建一个不和谐的机器人,我想通过一个命令创建一个新频道,在这个频道中发送一个带有各种功能的嵌入。 我尝试了几种方法,我可以在新创建的频道中获得要发送的默认消息,但是我无法让它调用向我发送嵌入的命令
这是我想在我通过命令 (setup.js) 创建的频道中发送的嵌入
module.exports = {
name: 'setup',
description: "ruoli con emote",
async execute(message, args, Discord, client){
const channel = '831573587579371580';
const playem = '⏯️';
const stopem = '⏹️';
const nextem = '⏭️';
//const shuffleem = '?';
const loopem = '?';
const volume15 = '?';
const volume30 = '?';
const mute= '?'
let embed = new Discord.MessageEmbed()
.setColor('#e42643')
.setTitle('Barman')
.setImage('https://images4.alphacoders.com/943/943845.jpg')
.setFooter('il prefisso del bot è: *');
console.log('message: ' + message )
console.log('args: ' + args)
console.log('Discord: ' + Discord)
console.log('client: ' + client)
let messageEmbed = await message.channel.send(embed);
messageEmbed.react(playem);
messageEmbed.react(stopem);
messageEmbed.react(nextem);
//messageEmbed.react(shuffleem);
messageEmbed.react(loopem);
messageEmbed.react(volume15);
messageEmbed.react(volume30);
messageEmbed.react(mute);
client.on('messageReactionAdd', async (reaction, user) =>{
if (reaction.message.partial) await reaction.message.fetch();
if (reaction.partial) await reaction.fetch();
if (user.bot) return;
if (!reaction.message.guild) return;
if (reaction.message.channel.id == channel){
switch(reaction.emoji.name){
case playem:
console.log('Pausa / resume');
client.commands.get('psres').execute(client, message, args);
break;
case stopem:
console.log('stop');
client.commands.get('stop').execute(client, message, args);
break;
case nextem:
console.log('Skip');
client.commands.get('skip').execute(client, message, args);
break;
case loopem:
console.log('loop');
client.commands.get('loop').execute(client, message, args)
break;
case volume15:
console.log('volume15');
client.commands.get('volume15').execute(client, message, args)
break;
case volume30:
console.log('volume30');
client.commands.get('volume30').execute(client, message, args)
break;
case mute:
console.log('muto');
client.commands.get('mute').execute(client, message, args)
break;
}
}
});
}
}
这是我的创作频道功能
if(command === 'setup'){
var botname= 'DJ Musica' // setup messaggio con reazioni
message.guild.channels.create(botname,{ //Create a channel
type: 'text', //Make sure the channel is a text channel
permissionOverwrites: [{ //Set permission overwrites
id: message.guild.id,
allow: ['VIEW_CHANNEL'],
}]
}).then(channel => channel.send('eccoci ' + message.channel.id))
答案 0 :(得分:0)
如果我没记错的话,在机器人创建的频道中发送消息的代码是
message.guild.channels.create('CHANNEL NAME HERE', { reason: 'Needed a cool new channel' })
.then(channel => {
channel.send('MESSAGE HERE')
})
答案 1 :(得分:0)
discord.js guide 提供了一种动态处理命令的好方法。
为了设置它以执行模块,我按照 discord.js
指南创建了自己的动态命令处理程序。有了这个,我可以轻松调用命令并简单地执行它。
代码:
const fs = require("fs"); //used to read files
const Discord = require('discord.js');
const client = new Discord.Client();
client.commands = new Discord.Collection();
//returns array of files in directory that read w/ end of ".js"
const commandFiles = fs.readdirSync('./commands').filter(file => file.endsWith('.js'));
for (const file of commandFiles) {
const command = require(`./commands/${file}`);
client.commands.set(command.name, command);
console.log(command);
}
client.on('message', message => {
const prefix = '!';
if (message.author.bot) return;
const args = message.content.slice(prefix.length).trim().split(/ +/);
const command = args.shift().toLowerCase();
if (!client.commands.has(command)) return;
if (command === 'setup') {
var botname = 'DJ Musica' // setup messaggio con reazioni
message.guild.channels.create(botname, { //Create a channel
type: 'text', //Make sure the channel is a text channel
permissionOverwrites: [{ //Set permission overwrites
id: message.guild.id,
allow: ['VIEW_CHANNEL'],
}]
}).then(channel => { //main part I modified
channel.send('eccoci ' + message.channel.id);
client.commands.get(command).execute(message, args, Discord, new Discord.Client());
})
}
});