Example #1
0
        public override async Task BeforeExecutionAsync(CommandContext ctx)
        {
            var vs  = ctx.Member.VoiceState;
            var chn = vs?.Channel;

            if (chn == null)
            {
                await ctx.RespondAsync($"{DiscordEmoji.FromName(ctx.Client, ":msraisedhand:")} You need to be in a voice channel.");

                throw new CommandCancelledException();
            }

            var mbr = ctx.Guild.CurrentMember?.VoiceState?.Channel;

            if (mbr != null && chn != mbr)
            {
                await ctx.RespondAsync($"{DiscordEmoji.FromName(ctx.Client, ":msraisedhand:")} You need to be in the same voice channel.");

                throw new CommandCancelledException();
            }

            this.GuildMusic = await this.Music.GetOrCreateDataAsync(ctx.Guild);

            this.GuildMusic.CommandChannel = ctx.Channel;

            await base.BeforeExecutionAsync(ctx);
        }
        public override async Task BeforeExecutionAsync(CommandContext ctx)
        {
            var vs  = ctx.Member.VoiceState;
            var chn = vs.Channel;

            if (chn == null)
            {
                await ctx.RespondAsync($"You need to be in a voice channel.");

                throw new CommandCancelledException();
            }

            var mbr = ctx.Guild.CurrentMember?.VoiceState?.Channel;

            if (mbr != null && chn != mbr)
            {
                await ctx.RespondAsync($"You need to be in the same voice channel.");

                throw new CommandCancelledException();
            }

            if (ctx.Command.CustomAttributes.OfType <RequiresMusicHostAttribute>().Any())
            {
                if (!ctx.Channel.PermissionsFor(ctx.Member).HasPermission(Permissions.ManageGuild))
                {
                    if (this.GuildMusic.Host != null && this.GuildMusic.Host != ctx.Member)
                    {
                        await ctx.RespondAsync("You aren't the host (Debug Message)");

                        throw new CommandCancelledException();
                    }
                }
            }

            this.GuildMusic = await this.Music.GetOrCreateDataAsync(ctx.Guild);

            this.GuildMusic.CommandChannel ??= ctx.Channel;
            this.GuildMusic.Host ??= ctx.Member;

            await base.BeforeExecutionAsync(ctx);
        }