是否可以使用自定义漫游器

时间:2019-05-29 03:49:50

标签: c# discord discord.net

我是Discord.Net API的新手,对它非常了解。但是我在将由机器人创建的频道移至现有类别频道时遇到了问题。如果我可以使用可以的通道ID,但理想情况下,它将找到一个名为“ user-reports”的类别,并从中获取ID来设置通道的父对象或位置。

//This is what i have to create a channel for testing purposes
var test = await Context.Guild.CreateTextChannelAsync("HI");

//I used this previously to find if a message was sent in a specific channel then it would act
 if (Context.Channel.Name != "report-user")
            {
                await Context.User.SendMessageAsync(Context.User + " You have tried to send a ticket to the wrong channel. Please use the report-user channel");
                return;
            }

1 个答案:

答案 0 :(得分:0)

    //Find the ID for the desired category 
    var categoryId = Context.Guild.CategoryChannels.FirstOrDefault(category => category.Name.Equals("user-reports"))?.Id;

    //Set channel category during channel creation
    await Context.Guild.CreateTextChannelAsync("Hi", prop => prop.CategoryId = categoryId);

    //Set channel category after channel creation
    var channel = await Context.Guild.CreateTextChannelAsync("Hello");
    await channel.ModifyAsync(prop => prop.CategoryId = categoryId);