我正在使用 C# 中的 Discord.Net 来制作一个机器人。到目前为止,我的机器人运行得非常好,但我希望它在用户加入特定服务器时自动为他们分配特定角色。我从未真正学过任何 C#,只学过一点 C++,所以我知道基本语法。我该怎么办呢?
我假设我会使用 UserJoined,但这样做会导致结果告诉我在 += 或 -+ 之前或之后使用它(我理解,但我不明白它在这个给定场景中的用处)
您提供的信息很少,但以下是如何在所有版本中执行此操作(到目前为止):
这是在依赖关系图中,但位于“handlecommand”、CommandHandleAsync 或 HandleCommandAsync 下方:
client.UserJoined += AnnounceJoinedUser; //Hook into the UserJoined event of the client.
这是在依赖关系图下:
public async Task AnnounceJoinedUser(SocketGuildUser user) //Welcomes the new user
{
var channel = client.GetChannel(/*/TextChannelID/*/) as SocketTextChannel; // Gets the channel to send the message in
await channel.SendMessageAsync($"Welcome {user.mention} to {channel.Guild.Name}"); //Welcomes the new user
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)