node.js - 如果第一种失败,则选择第二种响应方式
问题描述
基本上,我使用一个以“新方式”响应的文件,更多称为内联回复,只有一个问题,如果在机器人发送消息之前删除了usuary的消息,它会message_reference
报错,我创建的表单它使用 message.channel.send 是这样的:
const msg = await message.inlineReply(embed).catch(async() => { message.channel.send(embed) })
但是如果你使用带有反应的异步是错误的,并且如果代码中有错误,则捕获受限于 message.channel.send 的捕获。有没有更有效的方法?也许改变 inlinereply.js 中的某些内容?
内联回复.js:
const { APIMessage, Structures } = require("discord.js");
class Message extends Structures.get("Message") {
async inlineReply(content, options) {
const mentionRepliedUser = typeof ((options || content || {}).allowedMentions || {}).repliedUser === "undefined" ? true : ((options || content).allowedMentions).repliedUser;
delete ((options || content || {}).allowedMentions || {}).repliedUser;
const apiMessage = content instanceof APIMessage ? content.resolveData() : APIMessage.create(this.channel, content, options).resolveData();
Object.assign(apiMessage.data, { message_reference: { message_id: this.id } });
if (!apiMessage.data.allowed_mentions || Object.keys(apiMessage.data.allowed_mentions).length === 0)
apiMessage.data.allowed_mentions = { parse: ["users", "roles", "everyone"] };
if (typeof apiMessage.data.allowed_mentions.replied_user === "undefined")
Object.assign(apiMessage.data.allowed_mentions, { replied_user: mentionRepliedUser });
if (Array.isArray(apiMessage.data.content)) {
return Promise.all(apiMessage.split().map(x => {
x.data.allowed_mentions = apiMessage.data.allowed_mentions;
return x;
}).map(this.inlineReply.bind(this)));
}
const { data, files } = await apiMessage.resolveFiles();
return this.client.api.channels[this.channel.id].messages
.post({ data, files })
.then(d => this.client.actions.MessageCreate.handle(d).message);
}
}
Structures.extend("Message", () => Message);
解决方案
推荐阅读
- java - 在 gremlin 服务器脚本文件中使用自定义库
- mysql - 是否可以在不重新启动 mysql 的情况下修改 logrotate 路径?
- android - 从 Android Gradle 访问 Azure DevOps 变量
- networking - Ubuntu 18.04(ESXi 6.7 上的来宾)中随机时间后的接口阻塞连接
- javascript - Chrome 上下文菜单扩展:将选定的文本保存到变量中
- r - 哪种是按列值聚合行(总和)的最简单方法是 R 上以下类型的数据框?
- kubernetes - Kubernetes 服务中是否有故障转移功能?
- javascript - React Native - 我无法使用 fetch 发送任何 FormData
- c# - HTML to Doc:在表格之间添加最小空间
- python - 无法删除列表中的“某些”空项目