Discord.Addons.CommandCache 2.0.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package Discord.Addons.CommandCache --version 2.0.0                
NuGet\Install-Package Discord.Addons.CommandCache -Version 2.0.0                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Discord.Addons.CommandCache" Version="2.0.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Discord.Addons.CommandCache --version 2.0.0                
#r "nuget: Discord.Addons.CommandCache, 2.0.0"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Discord.Addons.CommandCache as a Cake Addin
#addin nuget:?package=Discord.Addons.CommandCache&version=2.0.0

// Install Discord.Addons.CommandCache as a Cake Tool
#tool nuget:?package=Discord.Addons.CommandCache&version=2.0.0                

Discord.Addons.CommandCache

A Discord.Net addon to autodelete command responses when the command message is deleted.

Usage

The built in CommandCacheService stores message IDs, and is thread safe. It should fit most use cases, but you can create your own implementation using ICommandCache.

Adding the service

Either add it manually:

var services = new ServiceCollection();
services.AddSingleton(new CommandCacheService(_client));

Or use the extension method:

var services = new ServiceCollection();
_client = new DiscordSocketClient().UseCommandCache(services, 500, Log);

You can also have an instance with no size limit by passing CommandCacheService.UNLIMITED as capacity.

Using the cache in a module

In order to use the command cache in a module, you must add it to the module through Discord.Net's dependency injection. While this can be done manually, an easier method is to have your module derive from CommandCacheModuleBase<TCommandCache, TCacheKey, TCacheValue, TCommandContext>. This works with any implementation of ICommandCache<TKey, TValue>.

Because that's a quite verbose class name, this package also provides CommandCacheModuleBase<TCommandContext> which uses the default CommandCacheService.

You can then access the cache through the module's Cache property. Responding to commands through ReplyAsync will automatically add the messages to the cache.

Adding values to the cache outside modules

There are two ways to add a message to the cache without the ModuleBase extension. The first is by using the Add method:

var responseMessage = await textChannel.SendMessageAsync("This is a command response");
cache.Add(commandMessageId, responseMessage.Id);

The second is by using the SendCachedMessageAsync extension method:

await textChannel.SendCachedMessageAsync(cache, commandMessageId, "This is a command response");

This method only works with the default CommandCacheService and does not support adding multiple messages at once.

Disposing of the cache

The built in CommandCacheService uses a System.Threading.Timer internally, so you should call the Dispose method in your shutdown logic. An example method is provided in the example bot.

Example

Refer to the example bot for proper usage of the command cache.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp1.0 was computed.  netcoreapp1.1 was computed.  netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard1.3 is compatible.  netstandard1.4 was computed.  netstandard1.5 was computed.  netstandard1.6 was computed.  netstandard2.0 was computed.  netstandard2.1 was computed. 
.NET Framework net46 was computed.  net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen30 was computed.  tizen40 was computed.  tizen60 was computed. 
Universal Windows Platform uap was computed.  uap10.0 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
2.1.0 805 6/5/2019
2.0.0 1,320 3/31/2018

Bug fixes & and adds an extension of ModuleBase that makes the command cache easier to use.