Discord.NET分配角色 [英] Discord.NET assigning roles

查看:86
本文介绍了Discord.NET分配角色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图让我的discord机器人在用户输入命令'!stream'时将角色分配给用户,尤其对于c#和discord.net编程来说,我非常.现在,我有了应该在消息接收方法内部分配角色的代码.这可能不是最好的方法,但我现在不确定是否有更好的方法.无论如何,这是代码:

I am trying to get my discord bot to assign a role to a user when they input the command '!stream' I am very new to programming in c# and discord.net especially. Right now I have the code that should be assigning the role inside of a message received method. This probably isn't the best way to do it but I'm not super sure a better way right now. Anyways, here is the code:

IGuildUser user = (IGuildUser)arg.Author;
IRole role = ((IGuildChannel)arg.Channel).Guild.GetRole(theRoleID);
if (arg.Content == "!stream") {
    await (user as IGuildUser).AddRoleAsync(role);
}

我已确保用户和角色都获得了正确的用户和正确的角色.它也运行if语句,因为我已经在其中输出了.唯一似乎不起作用的是实际分配.任何帮助是极大的赞赏.谢谢!

I have made sure both user, and role is getting the correct user and correct role. Its also running the if statement because I had output inside of it. The only thing that doesn't seem to be working is the actual assignment. Any help is greatly appreciated. Thanks!

推荐答案

如果代码端的所有内容均已正常运行,则可能是Discord服务器本身存在权限问题,当我尝试进行一些审核时,这一次发生在我身上这对我的一生都没有用.事实证明,问题仅是不和谐服务器上的角色层次结构,基本上,机器人所处的角色只会影响其下方的人员,例如截图:

If everything on the code side is already working, you might have a permissions issue on the Discord server itself, happened to me once when trying to make some moderation happen and it didn't work for the life of me. Turns out the issue was simply the role hierarchy on the discord server, basically the role the bot is in can only affect those underneath him, take for example the screenshot:

您会发现在 Admin 角色的正下方有一个 Inquisition 角色.那是一个机器人,它必须位于其他角色之上才能与这些用户进行交互,因此,我建议您尝试将机器人移到角色阶梯上,看看是否可以解决您的问题.

You'll notice there's an Inquisition role right underneath the Admin one. That's a bot, which needs to be on top of every other role to be able to interact with those users, so I suggest you try and move your bot up the role ladder and see if that fixes your issue.

这篇关于Discord.NET分配角色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆