Files
Discord.Net/src/Discord.Net.Commands/Attributes/Preconditions/RequireGuildAttribute.cs
Finite Reality 11f1163ec2 Add Command and module instance parameters to CheckPermissions
After a small discussion with Joe4evr on discord, a way of retrieving the
state of a module appeared to be needed. The new override should provide
enough context to a bot dev to allow them to do what they want.
2016-08-04 23:31:21 +01:00

20 lines
701 B
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace Discord.Commands
{
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = false, Inherited = true)]
public class RequireGuildAttribute : PreconditionAttribute
{
public override Task<PreconditionResult> CheckPermissions(IMessage context, Command executingCommand, object moduleInstance)
{
if (!(context.Channel is IGuildChannel))
return Task.FromResult(PreconditionResult.FromError("Command must be used in a guild"));
return Task.FromResult(PreconditionResult.FromSuccess());
}
}
}