【发布时间】:2021-05-05 23:17:31
【问题描述】:
我正在执行一个 !user @ 命令,它提供了有关提到的用户的信息,但是在获取角色时我收到此错误 无法将“Discord.WebSocket.SocketGlobalUser”类型的对象转换为“Discord.WebSocket.SocketGuildUser”类型'。
这就是我的做法:
[Command("user")]
public async Task Info(string user)
var client = Context.Client;
ulong id = Convert.ToUInt64(user);
var socketUser = client.GetUser(id);
string a = string.Empty;
foreach (SocketRole role in ((SocketGuildUser)socketUser).Roles) //Problem is on this line
{
a += role.Mention + " ";
}
但它似乎不起作用。我试过 SocketUser 而不是 SocketGuildUser 但没有。 帮助
【问题讨论】:
-
你为什么不简单地接受 SocketGuildUser 作为你的命令参数?
-
你能显示你的 SocketGlobalUser 和 SocketGuildUser
标签: c# discord discord.net