Discord:使用.NET库更改区域?

问题描述 投票:1回答:1

我目前正在尝试使用机器人检查延迟来防止我的Discord服务器出现滞后,如果确实发生,则切换到另一个区域。我在js中看到了几个机器人,我想知道Discord.NET中是否能够做到这一点。当然,我一直在解析Google几个小时才找到方法。谢谢

c# discord region discord.net
1个回答
1
投票

你可以在ModifyAsync的一个实例上调用SocketGuild,并将RegionId属性设置为你想要的新区域。

//I'm doing this as a command, but the logic can be implemented wherever you decide.
[Command("region")]
[Remarks("Let's pretend my module has access to a singleton instance of random")]
public async Task ChangeRegion()
{
    //Get a collection of all available voice regions 
    //Exclude the region we are currently in
    var voiceRegions = Context.Client.VoiceRegions.Where(r => !r.Id.Equals(Context.Guild.VoiceRegionId));

    //Select a random new region
    var newRegion = voiceRegions(random.Next(voiceRegions.Count));

    //Update the RegionId property for the guild.
    await Context.Guild.ModifyAsync(prop => prop.RegionId = newRegion.Id)
    await ReplyAsync($"Region updated to {newRegion.Name}: {newRegion.Id}");
}
© www.soinside.com 2019 - 2024. All rights reserved.