使用Discord.NET,如何将交互响应记录到变量中?

huangapple go评论54阅读模式
英文:

Using Discord.NET, how do i record an interaction response into a variable?

问题

我最近遇到了一个问题,即无法使用典型的方法将交互响应记录到变量中以供以后处理,因为RespondAsync是一个async Task,不提供任何消息类型的输出。

我尝试在官方API和向AI提问中搜索,但没有找到任何有效的答案。
我还尝试了

var msg  = await Context.Interaction.RespondAsync(embed: Completed.Build()).MethodOrProperty;
//以及
var msg  = (await Context.Interaction.RespondAsync(embed: Completed.Build()) as AnyMessageType);

由于非常明显的原因,这两种方法都不起作用。

英文:

I recently stumbled across the issue that an interaction response cannot be recorded into a variable for latter handling with a typical method, var msg = await Context.Interaction.RespondAsync(embed: Completed.Build()); because RespondAsync is an async Task not giving any message type output.

I tried searching the official API as well as asking AI but haven't found any valid answer.
Also i tried

var msg  = await Context.Interaction.RespondAsync(embed: Completed.Build()).MethodOrProperty;
//as well as
var msg  = (await Context.Interaction.RespondAsync(embed: Completed.Build()) as AnyMessageType);

which didn't work for pretty obvious reasons.

答案1

得分: 2

如果您查看源代码,您会注意到评论最近已更改:

从:

> 代表异步发送操作以传递消息的任务。 任务结果包含发送的消息。

到:

> 代表异步发送操作以传递消息的任务。

此更改的拉取请求表示XML文档是一个错误,已经修复。

似乎没有包含消息的结果。

英文:

If you look at the source, you will notice that the comment has recently changed:

From:

> A task that represents an asynchronous send operation for delivering the message. The task result contains the sent message.

To:

>A task that represents an asynchronous send operation for delivering the message.

The Pull Request for this change says the XML documentation was a mistake and has been fixed.

It seems there is no result containing the message.

答案2

得分: 0

发现有 Context.Interaction.GetOriginalResponseAsync。希望对有相同问题的人有所帮助。

英文:

Found out that there is Context.Interaction.GetOriginalResponseAsync. Hope that helps anybody with the same issue.

huangapple
  • 本文由 发表于 2023年5月7日 14:55:02
  • 转载请务必保留本文链接:https://go.coder-hub.com/76192564.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定