首页 文章

Discord C#用户加入消息

提问于
浏览
3

我在C#中使用Discord.Net,制作机器人 . 到目前为止,我的机器人工作得非常好,但我希望它在加入特定服务器时自动为用户分配特定角色 . 我从来没有真正学过任何C#,只有一点C,所以我知道基本的语法 . 我该怎么做?我假设我会使用UserJoined,但这样做的结果告诉我在=或 - 之前或之后使用它(我理解,但我不明白它在这个给定的场景中是否有用)

1 回答

  • 4

    您提供的信息很少,但是这里是如何在所有版本中执行此操作(到目前为止):

    这是在依赖关系图中,但在“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
    }
    

相关问题