我正在尝试制作一个会创建临时语音通道的机器人
代码:
SELECT
SUM(`BENCH`.`ELEGIVEL`) AS `ELEGIVEL`,
SUM(`BENCH`.`ADESAO`) AS `ADESAO`,
`BENCH`.`ano` AS `ano`,
`BENCH`.`mes` AS `mes`,
'BENCHMARK' AS `TIPO`
FROM
(SELECT
SUM(`v`.`QuantidadeItem`) AS `ELEGIVEL`,
NULL AS `ADESAO`,
`v`.`ano` AS `ano`,
`v`.`mes` AS `mes`
FROM
`V_VENDAS_ELEGIVEIS` `v`
WHERE
((`v`.`nome_emp` LIKE '%ESB%')
AND (`v`.`data_lancamento` BETWEEN DATE_FORMAT((NOW() - INTERVAL 12 MONTH), '%Y-%m-01') AND LAST_DAY((CURDATE() - INTERVAL 1 MONTH))))
GROUP BY `v`.`ano` , `v`.`mes` UNION ALL SELECT
NULL AS `ELEGIVEL`,
COUNT(0) AS `ADESAO`,
`V_SEGUROS_ADESAO`.`Ano` AS `ano`,
`V_SEGUROS_ADESAO`.`Mes` AS `mes`
FROM
`V_SEGUROS_ADESAO`
WHERE
((`V_SEGUROS_ADESAO`.`nome_emp` LIKE '%ESB%')
AND (`V_SEGUROS_ADESAO`.`dataemissao` BETWEEN DATE_FORMAT((NOW() - INTERVAL 12 MONTH), '%Y-%m-01') AND LAST_DAY((CURDATE() - INTERVAL 1 MONTH))))
GROUP BY `V_SEGUROS_ADESAO`.`Ano` , `V_SEGUROS_ADESAO`.`Mes`) `BENCH`
GROUP BY `BENCH`.`ano` , `BENCH`.`mes`
为什么不起作用? 在我重新安装系统之前,它工作正常 节点:13.10.1 赢:10
答案 0 :(得分:2)
我可以看到您在异步代码方面遇到问题。您具有以下行:
await newMember.setVoiceChannel(channel.id)
这不是您所期望的那样,因为它属于.then
的块内。等待只会影响.then
语句中该异步块中的代码,并且由于在该行之后什么也没有发生,因此它在功能上与没有等待时没有做任何不同。
如果可能的话,您应尽量避免将.then和async / await混合使用(出于某些原因,您可能会混合使用,但您需要知道自己在做什么)。在这种情况下,我建议将整个事件处理程序设置为异步并等待两者。
注意:以下假设您使用的是discord.js v11,与先前的代码示例一致。如果您使用的是v12,则应改用guild.channels.create()
,guild.channels.cache.find()
和newMember.voice.setChannel()
。您说您刚刚安装了新的node和假定的discord.js实例,因此实际上您现在可能已安装在v12上,这可能是问题的一部分。
client.on('voiceStateUpdate', async (oldMember, newMember) => {
const mainCatagory = '677192265491415041';
const mainChannel = '677875869351542803';
if (newMember.voiceChannelID == mainChannel) {
let channel = await newMember.guild.createChannel(`${newMember.user.username} 5vs5`, { type: 'voice', parent: mainCatagory })
temporary.push({ newID: channel.id, guild: channel.guild })
// A new element has been added to temporary array!
await newMember.setVoiceChannel(channel.id)
}
// The rest of your code.
}