public async Task CreateCategoryAsync(CommandContext ctx, [Description("Channel to clone.")] DiscordChannel channel, [RemainingText, Description("Name for the cloned channel.")] string name = null) { var cloned = await channel.CloneAsync(ctx.BuildInvocationDetailsString()); if (!string.IsNullOrWhiteSpace(name)) { if (name.Length > 100) { throw new InvalidCommandUsageException("Channel name must be shorter than 100 characters."); } if (channel.Type == ChannelType.Text && name.Contains(' ')) { throw new CommandFailedException("Text channel name cannot contain spaces!"); } if (ctx.Guild.Channels.Values.Any(chn => chn.Name == name.ToLowerInvariant())) { if (!await ctx.WaitForBoolReplyAsync("Another channel with that name already exists. Continue?")) { return; } } await cloned.ModifyAsync(new Action <ChannelEditModel>(m => m.Name = name)); } await this.InformAsync(ctx, $"Successfully created clone of channel {Formatter.Bold(channel.Name)} with name {Formatter.Bold(cloned.Name)}.", important : false); }
public async Task PurgeChatAsync(CommandContext ctx) { DiscordChannel channel = ctx.Channel; var z = ctx.Channel.Position; var x = await channel.CloneAsync(); await channel.DeleteAsync(); await x.ModifyPositionAsync(z); var embed2 = new DiscordEmbedBuilder() .WithTitle("✅ Purged") .WithFooter($"foo"); await x.SendMessageAsync(embed : embed2); }
public async Task PurgeChatAsync(CommandContext ctx) { Serilog.Log.Debug("PC"); DiscordChannel channel = ctx.Channel; var z = ctx.Channel.Position; var x = await channel.CloneAsync(); await channel.DeleteAsync(); await x.ModifyPositionAsync(z); var embed2 = new DiscordEmbedBuilder() .WithTitle("✅ Purged") .WithFooter($"(C) 𝖆𝖇𝖓𝖔𝖗𝖒𝖆𝖑#0666, foo"); await x.SendMessageAsync(embed : embed2); }
public async Task SendMessage(CommandContext ctx, [Description("Channel to clone.")] DiscordChannel channel, [Description("Name of the cloned channel.")] string name, [Description("Additional roles to view this channel")] params DiscordRole[] roles) { DiscordChannel?cloned = null; try { cloned = await channel.CloneAsync(); } catch (Exception e) { _logger.LogError(e, "Failed to clone channel {0} with name {1}.", channel, name); await ctx.Message.CreateReactionAsync(DiscordEmoji.FromName(ctx.Client, ":-1:")); } await cloned !.ModifyAsync(model => { model.Name = name; model.Position = channel.Position; }); foreach (DiscordRole role in roles) { try { await cloned.AddOverwriteAsync(role, Permissions.AccessChannels); } catch (Exception e) { _logger.LogWarning(e, "Failed to grant access to role {0} in channel {1}.", role, channel); } } await ctx.Message.CreateReactionAsync(DiscordEmoji.FromName(ctx.Client, ":+1:")); }
public async Task AddNewVoiceChannelAsync( DiscordChannel channelToCloneFrom, DiscordMember member, string?name, int?limit, bool?isPublic) { name = ConvertStringToValidState(name); try { string? userName = ConvertStringToValidState(member.Nickname, member.Username); DiscordChannel newChannel = await channelToCloneFrom.CloneAsync($"Member {userName} created new voice channel."); await EditChannelAsync(false, newChannel, name, limit, isPublic, userName); try { if (member.VoiceState?.Channel != null) { await member.PlaceInAsync(newChannel); } } catch { // User disconnected while we were placing them. } // Placing the member in the channel failed, so remove it after some time. Task _ = Task.Run(async() => { await Task.Delay(1000 * _voiceConfig.RemoveAfterCommandInSeconds); await DeleteUnusedVoiceChannelAsync(newChannel); }); } catch (Exception e) { _logger.LogError(e, "Creating voice channel failed"); } }
public async Task CloneChannelAsync(CommandContext ctx, DiscordChannel chan = null) { chan = chan ?? ctx.Channel; await chan.CloneAsync().ConfigureAwait(false); }