Не могу назначить роли discord.net - PullRequest
0 голосов
/ 05 мая 2019

Я тестировал этот код вчера, и он отлично работал, но сегодня что-то пошло не так, и я не знаю, где.

Бот автоматически отправляет сообщение, добавляет 1 реакцию, но проблема в том, что покареагируя на отсутствие назначенной роли.

Мой код:

Imports Discord
Imports Discord.WebSocket
Imports Discord.Rest

Dim discord As DiscordSocketClient
Public ReactionMessages As ULong

Public token_ As String = "Token_Hiden"

Public Async Function onMsg(message As SocketMessage) As Task
    If message.Source = MessageSource.Bot Then
        Dim reaction As SocketReaction
        Dim rMessage = CType(Await message.Channel.GetMessageAsync(message.Id), RestUserMessage)

        If reaction.Emote.Name.Equals("?") AndAlso
            reaction.Emote.Name.Equals("?") Then
        End If

    End If


Private Async Function ReactionAdded(cache As Cacheable(Of IUserMessage, ULong), channel As ISocketMessageChannel, reaction As SocketReaction) As Task
    If Not reaction.User.IsSpecified Then Return

    If ReactionMessages.Contains(cache.Id) Then
        Dim role As IRole = Nothing

        If reaction.Emote.Name.Equals("?") Then

            role = DirectCast(channel, SocketGuildChannel).Guild.Roles.FirstOrDefault(Function(x) x.Name = "one")
        ElseIf reaction.Emote.Name.Equals("?") Then

            role = DirectCast(channel, SocketGuildChannel).Guild.Roles.FirstOrDefault(Function(x) x.Name = "two")
        End If

        If role IsNot Nothing Then Await DirectCast(reaction.User.Value, SocketGuildUser).AddRoleAsync(role)
    End If
End Function

     Private Async Function ReactionRemoved(cache As Cacheable(Of IUserMessage, ULong), channel As ISocketMessageChannel, reaction As SocketReaction) As Task
    If Not reaction.User.IsSpecified Then Return

    If ReactionMessages.Contains(cache.Id) Then
        Dim role As IRole = Nothing
        Dim user As SocketGuildUser = reaction.User.Value

        If reaction.Emote.Name.Equals("?") Then

            role = DirectCast(channel, SocketGuildChannel).Guild.Roles.FirstOrDefault(Function(x) x.Name = "one")
        ElseIf reaction.Emote.Name.Equals("?") Then

            role = DirectCast(channel, SocketGuildChannel).Guild.Roles.FirstOrDefault(Function(x) x.Name = "two")
        End If

        If role IsNot Nothing AndAlso user.Roles.Any(Function(r) r.Id = role.Id) Then Await user.RemoveRoleAsync(role)
    End If
End Function



Private Async Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

        Dim builder = New EmbedBuilder
        builder.WithTitle("test")
        builder.AddField("title!", "not much")
        builder.WithThumbnailUrl(discord.CurrentUser.GetAvatarUrl)
        builder.WithColor(124, 54, 42)

        Dim msgg = Await discord.GetGuild("426511769687556100").GetTextChannel("534344526848851988").SendMessageAsync("", False, builder)
        Dim my_emo1 As New Emoji("?")
        Dim my_emo2 As New Emoji("?")

        Await msgg.AddReactionAsync(my_emo1)
        Await msgg.AddReactionAsync(my_emo2)
End Sub

Этот код работал вчера, но я, возможно, немного его изменил.Если пользователь реагирует на новое сообщение, ничего не происходит.

1 Ответ

1 голос
/ 05 мая 2019

выяснить, что нужно добавить,

ReactionMessages = msg.Id 'after Await Msg, [single msg track id]

ReactionMessages.Add(msg.Id) 'after Await Msg, [Multi msgs track id] By @Anu6is| Thanks.
...