正在尝试将消息从一个频道重定向到另一个频道



我在下面的代码中得到了这个错误:

(节点:13760(未处理的PromiseRejectionWarning:TypeError:无法读取未定义的属性"send">


bot.on('message', async (message) => {
message
.delete({ timeout: 10 })
.catch((err) =>
logger.error(`Could not delete message (Error: ${err.message})`),
);
// Checking if command was executed in report channel
if (message.channel.name != 'from-user') {
// Do nothing
logger.info(
`message has not been sent in the forwarding channel! Aborting request.`,
);
} else {
if (message.author.bot) return;
await client.channels.cache.get('910109122572218378').send(message.content);
console.log(message.content); // log messages
return;
}
});

如果通道ID正确,则可能未缓存通道。如果你知道频道ID,你可以用这个IDfetch频道。如果它被缓存了,它会返回缓存的频道:

const channel = await client.channels.fetch(CHANNEL_ID)
await channel.send(message.content)
console.log(message.content) // log messages

fetch()返回Promise,因此需要使用await

相关内容

最新更新