【发布时间】:2019-02-08 18:15:57
【问题描述】:
我试图让我的 discord 机器人在用户输入命令“!stream”时为其分配角色现在我有应该在消息接收方法中分配角色的代码。这可能不是最好的方法,但我现在不确定更好的方法。无论如何,这是代码:
IGuildUser user = (IGuildUser)arg.Author;
IRole role = ((IGuildChannel)arg.Channel).Guild.GetRole(theRoleID);
if (arg.Content == "!stream") {
await (user as IGuildUser).AddRoleAsync(role);
}
我已确保用户和角色都获得了正确的用户和正确的角色。它也运行 if 语句,因为我在其中有输出。唯一似乎不起作用的是实际分配。任何帮助是极大的赞赏。谢谢!
【问题讨论】:
标签: c# discord discord.net