【问题标题】:Discord YAGPDB.xyz Bot Custom Command: Get Message from ID (golang)Discord YAGPDB.xyz Bot 自定义命令:从 ID 获取消息(golang)
【发布时间】:2022-01-20 07:10:49
【问题描述】:

我既是 Discord 又是 Golang 新手,遇到了问题。

我正在尝试帮助某人创建自定义命令,以让 Discord 的 YAGPDB.xyz 机器人将消息从一个线程移动到另一个线程。主脚本执行实际工作,但输出有点错误:我们希望它输出消息的实际所有者(和时间戳),但它声明我(运行命令的人)是所有者。

我已将其范围缩小到这样一个事实,即当我将消息 ID 作为参数时,它保持为 int,我需要获取/实例化消息,以便我可以访问其属性,如作者,根据对此: https://docs.yagpdb.xyz/commands/custom-commands#the-message-template 似乎没有“消息”类型的特定参数,尽管有诸如 channelmember 之类的东西: https://docs.yagpdb.xyz/commands/custom-commands#require-arguments

所以我创建了一个测试脚本只是为了获取消息的作者详细信息:

{{$args := parseArgs 1 "Syntax is : '!getauthor (.MessageID to move)'"
    (carg "int" "message ID")}}

{{$message:= ($args.Get 0)}}
{{$message.Author}}

这是输出:

An error caused the execution of the custom command template to stop:
Failed executing CC #9, line 5, row 10: executing "CC #9" at <$message.Author>: can't evaluate field Author in type int
4    {{$message:= ($args.Get 0)}}
5    {{$message.Author}}

任何帮助表示赞赏。

【问题讨论】:

    标签: discord


    【解决方案1】:

    getMessage做的

    {{$args := parseArgs 2 "Syntax is : '!move-msg (.MessageID to move) (.ChannelID Source Channel ID)'"
        (carg "int" "message ID")
            (carg "int" "source channel ID")}}
     
    {{$messageId := $args.Get 0}}
    {{$sourceChannelId := $args.Get 1}}
    {{$message := getMessage $sourceChannelId $messageId}}
    
    Author: {{$message.Author.Username}}, Created: {{$message.Timestamp.Parse.String}}
    

    打印出来:

    Author: xxxxx, Created: 2021-12-16 22:14:33.586 +0000 UTC
    

    【讨论】:

      猜你喜欢
      • 2017-08-31
      • 2021-04-11
      • 2021-12-12
      • 1970-01-01
      • 2022-01-05
      • 2021-08-12
      • 2021-12-20
      • 2022-08-14
      • 2021-07-19
      相关资源
      最近更新 更多