Discord 2.0清除消息(vb.net)

时间:2019-01-23 08:32:04

标签: vb.net discord.net

我正在编写一个简单的Discord机器人,清除了我频道的信息。 但是我遇到了错误,而且我不知道如何找出导致错误的原因。 这是完整的代码。

Imports Discord
Imports Discord.Commands
Imports Discord.WebSocket

<Group("purge")>
Public Class cmd_testcmd
    Inherits ModuleBase
    <Command>
    Public Async Function DelMsg(amount As Integer) As Task

        Try

            Dim msgs = Context.Channel.GetMessagesAsync(amount)
            Dim msg As IMessage = msgs

            Await msg.DeleteAsync(Await msgs.FlattenAsync)

        Catch ex As Exception
            Console.WriteLine("[Test] " & ex.Message)
        End Try

    End Function
End Class

因此,当我输入!purge 99时,它应该删除99条消息。 错误:

[Test] Unable to cast object of type 'Concat2AsyncIterator`1[System.Collections.Generic.IReadOnlyCollection`1[Discord.IMessage]]' to type 'Discord.IMessage'.

1 个答案:

答案 0 :(得分:0)

  

无法将类型为“ Concat2AsyncIterator1 [System.Collections.Generic.IReadOnlyCollection1 [Discord.IMessage]]”的对象强制转换为“ Discord.IMessage”

错误明确指出:msgs不是单个IMessage,而是IMessage的集合

Dim msgs = Context.Channel.GetMessagesAsync(amount)
Dim msg As IEnumerable(of IMessage) = Await msgs.FlattenAsync()

Await Context.Channel.DeleteAsync(msg)