Discord.NET sending messages to one specific channel in one specific server

对着背影说爱祢 提交于 2019-12-11 06:09:48

问题


So I'm trying to send a message to a specific channel, but I've been looking and found I can't see any way I can do that. I might be doing something wrong or I'm looking in the wrong area, I've looked on Google and couldn't find an answer. This is my code when trying to find it.

     discord.GetGuild("serverid").GetChannel("Channelid")

As far as I can see, this is not the way to do it, but I don't know where else to check :\


回答1:


Actually, I kinda feel stupid after realizing this, In my code previously, I was making the program try and find a channel, when what I actually needed to do was find a text channel, like so:

    discord.GetGuild("serverid").GetTextChannel("Channelid").SendMessageAsync(
    "Message")

So sorry for asking for help when the answer was really simple. :/




回答2:


when getting the channel you dont need to get the guild, all channels is inside your client so discord.GetTextChannel("id").SendMessageAsync("message") would be enough



来源:https://stackoverflow.com/questions/47884627/discord-net-sending-messages-to-one-specific-channel-in-one-specific-server

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