Discord C# User Join messages

回眸只為那壹抹淺笑 提交于 2019-12-20 02:05:49

问题


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)


回答1:


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

This is IN the dependency map but below the "handlecommand", CommandHandleAsync or HandleCommandAsync:

client.UserJoined += AnnounceJoinedUser; //Hook into the UserJoined event of the client.

This is under the dependency map:

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
} 


来源:https://stackoverflow.com/questions/43443658/discord-c-sharp-user-join-messages

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!