我正在尝试创建一个不和谐的bot,该bot在其他通道之间创建通道,但是我无法实现它,因为我的代码应该创建一个通道,但是...我尝试了很多事情,这是两个避风港没有给我错误:(我用DONOTLOOK代替了机器人的令牌,我不会遇到问题...)
选项1:
const Discord = require('discord.js');
const bot = new Discord.Client();
bot.login('DONOTLOOK');
bot.on('ready', () => {
console.log('Logged in as ${bot.user.tag}!');
});
bot.on('message', msg => {
if (msg.content === 'ping') {
msg.reply('Pong!');
var server = msg.guild;
bot.channels.add("anewchannel", {type: 0});
}
});
选项2:
const Discord = require('discord.js');
const bot = new Discord.Client();
bot.login('DONOTLOOK');
bot.on('ready', () => {
console.log(`Logged in as ${bot.user.tag}!`);
});
bot.on('message', msg => {
if (msg.content === 'ping') {
msg.reply('Pong!');
var server = msg.guild;
const channel = bot.channels.add("newchannel", {type: 0});
}
});
那在控制台上没有给我任何node.js错误,机器人回答了我,但是还没有创建频道。我还查看了两个引用(https://discord.com/developers/docs/resources/guild#create-guild-channel,https://discord.js.org/#/docs/main/stable/class/GuildChannelManager?scrollTo=create),没人能解决,discord.com也给了我node.js错误。上面的两个选项取自discord.js文件,它们没有出现node.js错误,但没有创建通道。如果有人可以帮助我。
答案 0 :(得分:1)
bot.on('message', msg => {
if (msg.content === 'channel') {
message.guild.channels.create('Text', {
type: 'text',
permissionOverwrites: [
{
id: message.guild.id,
allow: ['VIEW_CHANNEL'],
}]
})
message.channel.send("Channel Created!)
}
});