我正在尝试对我的命令进行确认部分,如果您激活该命令,则需要在代码激活之前说“是”。再次出现的问题是消息后面的代码
已确认...请稍候。
在此之后,它完全跳过代码并且什么也不做。当我在 VSC 中编写代码时,async
代码部分不是用黄色突出显示的,而是更深的黄色。
我已经尝试删除这部分代码
const async = async () => {
但是除非它连接到异步,否则带有等待的代码无法运行。我试过改变异步的运行方式。
async () => {
结果还是一样。删除开始的异步代码也只会导致命令中断。我已经将大块代码放在代码之外then(collected
,但是在命令激活时等待几秒钟后,它立即运行,然后出现值错误。但我希望它在作者说“是”时激活代码
async run(message, args){
if (message.channel instanceof Discord.DMChannel) return message.channel.send('This command cannot be executed here.')
let replyMessage = message.reply('Please make sure that my integration role "Synthibutworse" is above the default role used for this server. Is this correct? [Reply with "YES"] if so. Will expire in 20 seconds...');
let filter = msg => msg.author.id == message.author.id && msg.content.toLowerCase() == 'yes';
message.channel.awaitMessages(filter, {max: 1, time: 20000}).then(collected => {
message.reply('Confirmed... Please wait.');
const async = async () => {
if(!message.member.guild.me.hasPermission(['MANAGE_WEBHOOKS'])) return message.channel.send('I don\'t have the permissions to make webhooks, please contact an admin or change my permissions!')
if(!message.member.guild.me.hasPermission(['MANAGE_ROLES'])) return message.channel.send('I don\'t have the permissions to make roles, please contact an admin or change my permissions!')
if (!message.member.hasPermission(['MANAGE_WEBHOOKS'])) return message.channel.send('You need to be an admin or webhook manager to use this command.')
if (!message.member.hasPermission(['MANAGE_ROLES'])) return message.channel.send('You need to be an admin or role manager to use this command.')
const avatar = `https://cdn.discordapp.com/attachments/515307677656678420/557050444954992673/Generic5.png`;
const name2 = "SYNTHIBUTWORSE-1.0WOCMD";
let woaID = message.mentions.channels.first();
if(!woaID) return message.channel.send("Channel is nonexistant or command was not formatted properly. Please do s!woa #(channelname)");
let specifiedchannel = message.guild.channels.find(t => t.id == woaID.id);;
const hook = await woaID.createWebhook(name2, avatar).catch(error => console.log(error))
await hook.edit(name2, avatar).catch(error => console.log(error))
message.channel.send("Please do not tamper with the webhook or else the command implied before will no longer function with this channel.")
var role = message.guild.createRole({
name: `Synthibutworse marker v1.0`,
color: 0xcc3b3b,}).catch(console.error);
specifiedchannel.send("Created role...");
if(message.guild.roles.name == "Synthibutworse marker v1.0") {
role.setMentionable(false, 'SBW Ping Set.')
role.setPosition(1)
role.setPermissions(['CREATE_INSTANT_INVITE', 'SEND_MESSAGES'])
.then(role => console.log(`Edited role`))
.catch(console.error)};
message.channel.send("Role set up...");
const sbwrID = message.guild.roles.find(`Synthibutworse marker v1.0`);
let specifiedrole = message.guild.roles.find(r => r.id == sbwrID.id)
message.channel.send('Created Role... Please wait.');
message.guild.specifiedchannel.replacePermissionOverwrites({
overwrites: [
{
id: specifiedrole,
denied: ['SEND_MESSAGES'],
allowed: ['VIEW_CHANNEL'],
},
],
reason: 'Needed to change permissions'
});
var bot = message.client
bot.on('message', function(message) { {
if(webhook.name == `Synthibutworse marker`) return
if(message.channel.id == webhook.channelID) return
{let bannedRole = message.guild.roles.find(role => role.id === specifiedrole);
message.member.addRole(bannedRole)};
}});
}});
}};
module.exports = woa;
我希望该命令以异步方式运行,并在消息作者说“是”时继续执行代码,并且不会在Please wait.
消息处停止。
实际发生的是代码没有在Please wait
消息之后立即运行。