@@ -21,7 +21,7 @@ attributes.
|
|||||||
All commands belong to a Module. (See the below section for creating modules.)
|
All commands belong to a Module. (See the below section for creating modules.)
|
||||||
|
|
||||||
All commands in a module must be defined as an `Task`, with at least one argument,
|
All commands in a module must be defined as an `Task`, with at least one argument,
|
||||||
being the @Discord.IMessage representing the context of the command.
|
being the @Discord.IUserMessage representing the context of the command.
|
||||||
|
|
||||||
To add parameters to your command, add additional arguments to the `Task` of the command.
|
To add parameters to your command, add additional arguments to the `Task` of the command.
|
||||||
You are _not_ required to accept all arguments as `String`, they will be automatically parsed
|
You are _not_ required to accept all arguments as `String`, they will be automatically parsed
|
||||||
@@ -149,13 +149,13 @@ By default, the following Types are supported arguments:
|
|||||||
- IUser/IGuildUser
|
- IUser/IGuildUser
|
||||||
- IChannel/IGuildChannel/ITextChannel/IVoiceChannel/IGroupChannel
|
- IChannel/IGuildChannel/ITextChannel/IVoiceChannel/IGroupChannel
|
||||||
- IRole
|
- IRole
|
||||||
- IMessage
|
- IMessage/IUserMessage
|
||||||
|
|
||||||
### Creating a Type Readers
|
### Creating a Type Readers
|
||||||
|
|
||||||
To create a TypeReader, create a new class that imports @Discord and @Discord.Commands . Ensure your class inherits from @Discord.Commands.TypeReader
|
To create a TypeReader, create a new class that imports @Discord and @Discord.Commands . Ensure your class inherits from @Discord.Commands.TypeReader
|
||||||
|
|
||||||
Next, satisfy the `TypeReader` class by overriding `Task<TypeReaderResult> Read(IMessage context, string input)`.
|
Next, satisfy the `TypeReader` class by overriding `Task<TypeReaderResult> Read(IUserMessage context, string input)`.
|
||||||
|
|
||||||
>[!NOTE]
|
>[!NOTE]
|
||||||
>In many cases, Visual Studio can fill this in for you, using the "Implement Abstract Class" IntelliSense hint.
|
>In many cases, Visual Studio can fill this in for you, using the "Implement Abstract Class" IntelliSense hint.
|
||||||
|
|||||||
@@ -19,6 +19,6 @@ title: Samples
|
|||||||
|
|
||||||
[!code-csharp[Message to Channel](samples/faq/send_message.cs)]
|
[!code-csharp[Message to Channel](samples/faq/send_message.cs)]
|
||||||
|
|
||||||
#### Retrieving an IGuild from an IMessage
|
#### Retrieving an IGuild from an IUserMessage
|
||||||
|
|
||||||
[!code-csharp[Message to Guild](samples/faq/guild_from_message.cs)]
|
[!code-csharp[Message to Guild](samples/faq/guild_from_message.cs)]
|
||||||
@@ -33,8 +33,11 @@ public class Program
|
|||||||
// Discover all of the commands in this assembly and load them.
|
// Discover all of the commands in this assembly and load them.
|
||||||
await commands.LoadAssembly(Assembly.GetEntryAssembly());
|
await commands.LoadAssembly(Assembly.GetEntryAssembly());
|
||||||
}
|
}
|
||||||
public async Task HandleCommand(IMessage msg)
|
public async Task HandleCommand(IMessage paramMessage)
|
||||||
{
|
{
|
||||||
|
// Cast paramMessage to an IUserMessage, return if the message was a System message.
|
||||||
|
var msg = paramMessage as IUserMessage;
|
||||||
|
if (msg == null) return;
|
||||||
// Internal integer, marks where the command begins
|
// Internal integer, marks where the command begins
|
||||||
int argPos = 0;
|
int argPos = 0;
|
||||||
// Get the current user (used for Mention parsing)
|
// Get the current user (used for Mention parsing)
|
||||||
|
|||||||
@@ -2,6 +2,5 @@ public async Task SendMessageToChannel(ulong ChannelId)
|
|||||||
{
|
{
|
||||||
var channel = await _client.GetChannelAsync(ChannelId) as IMessageChannel;
|
var channel = await _client.GetChannelAsync(ChannelId) as IMessageChannel;
|
||||||
await channel?.SendMessageAsync("aaaaaaaaahhh!!!")
|
await channel?.SendMessageAsync("aaaaaaaaahhh!!!")
|
||||||
/* ^ This question mark is used to indicate that 'channel' may sometimes be null, and
|
/* ^ This question mark is used to indicate that 'channel' may sometimes be null, and in cases that it is null, we will do nothing here. */
|
||||||
in cases that it is null, we will do nothing here. */
|
|
||||||
}
|
}
|
||||||
@@ -6,10 +6,10 @@ public class AdminModule
|
|||||||
{
|
{
|
||||||
// ~admin mod ban foxbot#0282
|
// ~admin mod ban foxbot#0282
|
||||||
[Command("ban")]
|
[Command("ban")]
|
||||||
public async Task Ban(IMessage msg, IGuildUser user) { }
|
public async Task Ban(IUserMessage msg, IGuildUser user) { }
|
||||||
}
|
}
|
||||||
|
|
||||||
// ~admin clean 100
|
// ~admin clean 100
|
||||||
[Command("clean")]
|
[Command("clean")]
|
||||||
public async Task Clean(IMessage msg, int count = 100) { }
|
public async Task Clean(IUserMessage msg, int count = 100) { }
|
||||||
}
|
}
|
||||||
@@ -3,7 +3,7 @@ private IAudioClient _audio;
|
|||||||
|
|
||||||
// Create a Join command, that will join the parameter or the user's current voice channel
|
// Create a Join command, that will join the parameter or the user's current voice channel
|
||||||
[Command("join")]
|
[Command("join")]
|
||||||
public async Task JoinChannel(IMessage msg,
|
public async Task JoinChannel(IUserMessage msg,
|
||||||
IVoiceChannel channel = null)
|
IVoiceChannel channel = null)
|
||||||
{
|
{
|
||||||
// Get the audio channel
|
// Get the audio channel
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ public class Info
|
|||||||
{
|
{
|
||||||
// ~say hello -> hello
|
// ~say hello -> hello
|
||||||
[Command("say"), Description("Echos a message.")]
|
[Command("say"), Description("Echos a message.")]
|
||||||
public async Task Say(IMessage msg,
|
public async Task Say(IUserMessage msg,
|
||||||
[Unparsed, Description("The text to echo")] string echo)
|
[Unparsed, Description("The text to echo")] string echo)
|
||||||
{
|
{
|
||||||
await msg.Channel.SendMessageAsync(echo);
|
await msg.Channel.SendMessageAsync(echo);
|
||||||
@@ -20,7 +20,7 @@ public class Sample
|
|||||||
{
|
{
|
||||||
// ~sample square 20 ->
|
// ~sample square 20 ->
|
||||||
[Command("square"), Description("Squares a number.")]
|
[Command("square"), Description("Squares a number.")]
|
||||||
public async Task Square(IMessage msg,
|
public async Task Square(IUserMessage msg,
|
||||||
[Description("The number to square.")] int num)
|
[Description("The number to square.")] int num)
|
||||||
{
|
{
|
||||||
await msg.Channel.SendMessageAsync($"{num}^2 = {Math.Pow(num, 2)}");
|
await msg.Channel.SendMessageAsync($"{num}^2 = {Math.Pow(num, 2)}");
|
||||||
@@ -34,7 +34,7 @@ public class Sample
|
|||||||
// ~sample whois 96642168176807936 --> Khionu#8708
|
// ~sample whois 96642168176807936 --> Khionu#8708
|
||||||
[Command("userinfo"), Description("Returns info about the current user, or the user parameter, if one passed.")]
|
[Command("userinfo"), Description("Returns info about the current user, or the user parameter, if one passed.")]
|
||||||
[Alias("user", "whois")]
|
[Alias("user", "whois")]
|
||||||
public async Task UserInfo(IMessage msg,
|
public async Task UserInfo(IUserMessage msg,
|
||||||
[Description("The (optional) user to get info for")] IUser user = null)
|
[Description("The (optional) user to get info for")] IUser user = null)
|
||||||
{
|
{
|
||||||
var userInfo = user ?? await Program.Client.GetCurrentUserAsync();
|
var userInfo = user ?? await Program.Client.GetCurrentUserAsync();
|
||||||
|
|||||||
@@ -3,9 +3,9 @@ public class InfoModule
|
|||||||
{
|
{
|
||||||
// Constrain this command to Guilds
|
// Constrain this command to Guilds
|
||||||
[RequireContext(ContextType.Guild)]
|
[RequireContext(ContextType.Guild)]
|
||||||
public async Task Whois(IMessage msg, IGuildUser user) { }
|
public async Task Whois(IUserMessage msg, IGuildUser user) { }
|
||||||
|
|
||||||
// Constrain this command to either Guilds or DMs
|
// Constrain this command to either Guilds or DMs
|
||||||
[RequireContext(ContextType.Guild | ContextType.DM)]
|
[RequireContext(ContextType.Guild | ContextType.DM)]
|
||||||
public async Task Info(IMessage msg) { }
|
public async Task Info(IUserMessage msg) { }
|
||||||
}
|
}
|
||||||
@@ -8,7 +8,7 @@ public class RequireOwnerAttribute : PreconditionAttribute
|
|||||||
public readonly ulong OwnerId = 66078337084162048;
|
public readonly ulong OwnerId = 66078337084162048;
|
||||||
|
|
||||||
// Override the CheckPermissions method
|
// Override the CheckPermissions method
|
||||||
public override Task<PreconditionResult> CheckPermissions(IMessage context, Command executingCommand, object moduleInstance)
|
public override Task<PreconditionResult> CheckPermissions(IUserMessage context, Command executingCommand, object moduleInstance)
|
||||||
{
|
{
|
||||||
// If the author of the message is '66078337084162048', return success; otherwise fail.
|
// If the author of the message is '66078337084162048', return success; otherwise fail.
|
||||||
return Task.FromResult(context.Author.Id == OwnerId ? PreconditionResult.FromSuccess() : PreconditionResult.FromError("You must be the owner of the bot."));
|
return Task.FromResult(context.Author.Id == OwnerId ? PreconditionResult.FromSuccess() : PreconditionResult.FromError("You must be the owner of the bot."));
|
||||||
|
|||||||
@@ -3,5 +3,5 @@ public class AdminModule
|
|||||||
{
|
{
|
||||||
[Command("ban")]
|
[Command("ban")]
|
||||||
[RequirePermission(GuildPermission.BanMembers)]
|
[RequirePermission(GuildPermission.BanMembers)]
|
||||||
public async Task Ban(IMessage msg) { }
|
public async Task Ban(IUserMessage msg) { }
|
||||||
}
|
}
|
||||||
@@ -3,7 +3,7 @@ using Discord.Commands;
|
|||||||
|
|
||||||
public class BooleanTypeReader : TypeReader
|
public class BooleanTypeReader : TypeReader
|
||||||
{
|
{
|
||||||
public override Task<TypeReaderResult> Read(IMessage context, string input)
|
public override Task<TypeReaderResult> Read(IUserMessage context, string input)
|
||||||
{
|
{
|
||||||
bool result;
|
bool result;
|
||||||
if (bool.TryParse(input, out result))
|
if (bool.TryParse(input, out result))
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ Below is a table that compares most common 0.9 entities to their 1.0 counterpart
|
|||||||
| ChannelType.Voice | @Discord.IVoiceChannel | This applies only to Voice Channels in Guilds
|
| ChannelType.Voice | @Discord.IVoiceChannel | This applies only to Voice Channels in Guilds
|
||||||
| User | @Discord.IGuildUser | This applies only to users belonging to a Guild*
|
| User | @Discord.IGuildUser | This applies only to users belonging to a Guild*
|
||||||
| Profile | @Discord.ISelfUser
|
| Profile | @Discord.ISelfUser
|
||||||
| Message | @Discord.IMessage
|
| Message | @Discord.IUserMessage
|
||||||
|
|
||||||
\* To retrieve an @Discord.IGuildUser, you must retrieve the user from an @Discord.IGuild.
|
\* To retrieve an @Discord.IGuildUser, you must retrieve the user from an @Discord.IGuild.
|
||||||
[IDiscordClient.GetUserAsync](xref:Discord.IDiscordClient#Discord_IDiscordClient_GetUserAsync_System_UInt64_)
|
[IDiscordClient.GetUserAsync](xref:Discord.IDiscordClient#Discord_IDiscordClient_GetUserAsync_System_UInt64_)
|
||||||
|
|||||||
Reference in New Issue
Block a user