我一直有这个代码错误,因为 createChannel 部分试图在定义“newChannelRole”之前运行我知道这是由于异步函数的某些性质,但我似乎无法找出确保事情发生的正确方法为了。特别是因为它发生在我的代码的哪些部分似乎是随机的
async run(msg,args){
//get our guilds Information
let guildID = msg.guild.id;
let locationDataKey = guildID+"_mapData";
//Our Guild Settings
let settingMapKey = guildID+"_setting";
let settings = settingsMap.get(settingMapKey);
//load up our location Data Array
let locationDataArray = data.get(locationDataKey);
//make the new channel
let formatedNameDashes = args.name.replace(/ /g,"-");
let formatedNameSpace = args.name.replace(/-/g," ")
//make a role for the channel
let newChannelRole;
msg.guild.createRole({
name:formatedNameSpace
}).then( x => {
newChannelRole = x;
});
//Make the Channel and set the new permissions
//Everyone has none, NPCs and the unique channel role can see it/type/read history
msg.guild.createChannel(formatedNameDashes,{
type:'text',
permissionOverwrites:[
{
id:msg.guild.defaultRole,
deny: ['VIEW_CHANNEL','SEND_MESSAGES','READ_MESSAGE_HISTORY']
},
{
id:settings.npcRoleID,
allow:['VIEW_CHANNEL','SEND_MESSAGES','READ_MESSAGE_HISTORY']
},
{
id:newChannelRole.id,
allow:['VIEW_CHANNEL','SEND_MESSAGES','READ_MESSAGE_HISTORY']
}
]
}).then( channel => {
//move it into the category
let rpCategory = msg.guild.channels.get(settings.rpCategoryID)
channel.setParent(rpCategory);
});
//save the locationDataArray
data.set(locationDataKey,locationDataKey);
});
}
LEATH
SMILET
慕的地10843
相关分类