首页 > 解决方案 > 从特定频道中的特定消息中删除所有反应

问题描述

// remove reactions from sign up message
    command(client, 'noreactions', message => {
        client.channels.cache.get(channelBotTest).fetch(messageWSSignUp).reactions.removeAll().catch(error => 
            console.error('Failed to clear reactions: ', error)
        );
    })

到目前为止,这是我的代码。我希望能够在私人频道中运行一个命令,该命令将删除特定频道中特定消息的所有反应。

收到此错误:TypeError:无法读取未定义的属性“removeAll”

我不确定是否也需要定义频道?

请帮忙。

谢谢

标签: discord.js

解决方案


fetch()返回一个Promise而不是立即返回值。要从 Promise 中获取消息对象,您可以使用.then()回调或await关键字。

command(client, 'noreactions', message => {
    client.channels.cache.get(channelBotTest).fetch(messageWSSignUp).then(fetchedMessage => {
        fetchedMessage.reactions.removeAll().catch(error => 
            console.error('Failed to clear reactions: ', error)
        )
    }).catch(err => console.log('failed to fetch the message'))
})

推荐阅读