我试着做一些可以检测到的东西,当有提到的时候,这部分起作用了,并且发送它,在某种程度上也是这样。由于某些原因,我无法以任何方式获取或获取通道(833856168668561409),机器人可以查看该通道并向其发送消息,但它似乎找不到它。我不知道发生了什么,我也找不到任何答案。谢谢您的时间,代码显示在下面。
if (message.guild.id == 793079701929066517) {
if (message.mentions.members.size) {
var channel = client.channels.fetch("833856168668561409"); //Get log channel.
var webhooks = await channel.fetchWebhooks();
var webhook = webhooks.first();
await webhook.send(`**Ping detected:**\n${Util.cleanContent(message.content, message)}`, {
username: `${message.author.username}`,
avatarURL: `${message.author.avatarURL()}`,
})
}
}
发布于 2021-04-20 02:17:07
忘记为我所要求的频道制作网钩。基本上:
'Bot: I need a webhook for this channel'
'Discord: There is no webhook, so I will give an empty list.'
'Bot: Now I must use this to send a message'
'Bot: I cant...?!?!'
// Basically there is no webhook for it to send with.
发布于 2021-04-20 01:03:46
client.channels.fetch
返回一个Promise
。您应该对结果进行await
。
如果没有await
,则channel.fetchWebhooks
(channel
是Promise
)返回导致channel.fetchWebhooks is not a function
错误的undefined
。
const channel = await client.channels.fetch('833856168668561409')
没有理由再使用var
了。使用const
或let
。
https://stackoverflow.com/questions/67171011
复制相似问题