Discord C#用户加入消息 [英] Discord C# User Join messages

查看:183
本文介绍了Discord C#用户加入消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在C#中使用Discord.Net,制作了一个机器人.到目前为止,我的机器人的运行效果非常好,但是我希望它可以在用户加入特定服务器时自动为他们分配特定角色.我从未真正学习过任何C#,仅学习了一点C ++,所以我知道基本的语法.我将如何处理?我假设我会使用UserJoined,但是这样做会引起结果告诉我在+ =或-+之前或之后使用它(据我所知,但我不明白在这种情况下它的用处)

I'm using Discord.Net in C#, making a bot. My bot works fantastic so far, but I want it to automatically assign users a specific role when they join a specific server. I've never actually learned any C#, only a bit of C++ so I know the basic Grammar. How would I go about this? I'm assuming I would use UserJoined, but doing this heeds results telling me to use it before or after a += or -+ (Which I understand, but I don't understand it's usefullness in this given scenario)

推荐答案

您提供的信息很少,但是以下是到目前为止所有版本中的操作方法:

You gave little information to work with but here is how to do it in all releases (so far):

这在依赖关系映射中,但在"handlecommand",CommandHandleAsync或HandleCommandAsync之下:

This is IN the dependency map but below the "handlecommand", CommandHandleAsync or 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
} 

这篇关于Discord C#用户加入消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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