【问题标题】:Discord: Change region using .NET library?Discord:使用 .NET 库更改区域?
【发布时间】:2019-09-19 05:30:04
【问题描述】:

我目前正在尝试使用机器人检查延迟来防止我的 Discord 服务器出现延迟,并在发生延迟时切换到另一个区域。我在 js 中看到了几个机器人这样做,我想知道 Discord.NET 中是否有一些东西能够做到这一点。当然,我已经解析谷歌几个小时来找到一种方法。 谢谢

【问题讨论】:

    标签: c# discord region discord.net


    【解决方案1】:

    您可以在SocketGuild 的实例上调用ModifyAsync,并将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}");
    }
    

    【讨论】:

      猜你喜欢
      • 2019-04-15
      • 1970-01-01
      • 2023-04-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多