Прежде всего, для создания команд в целом, вы должны рассмотреть возможность использования Служба команд , которая предоставляется в Discord.Net, вместо проверки If / Else в вашем обработчике событий, полученных сообщениями.,
В вашем коде также есть ошибка.Вы объявляете переменную userName
, но фактически никогда ничего ей не назначаете.Тем не менее вы пытаетесь сделать userName.Roles
Решение:
If message.Source = MessageSource.Bot Then
Return
ElseIf message.Content.Contains("test") Then
Dim user = TryCast(message.Author, SocketGuildUser)
'If casting the user to a SocketGuildUser was not successful, then exit
If user Is Nothing Then Return 'This can occur if a user message the bot via Direct Messages
'Using "Any" returns true if a match is found, false otherwise
If user.Roles.Any(Function(role) role.Name.Equals("VIP", StringComparison.OrdinalIgnoreCase)) Then
Await message.Channel.SendMessageAsync("you have permission")
Else
Await message.Channel.SendMessageAsync("you dont have permission")
End If
End If