Cache Choices

Internally all data is ‘cached’ using an implementation which implements antispam.abc.Cache

In the standard package you have the following choices:

In order to use a cache other then the default one, simply pass in an instance of the cache you wish to use with the cache kwarg when initialising your AntiSpamHandler.

Alternately, use the AntiSpamHandler.set_cache method.

Here is an example, note MongoCache needs a extra argument.

 1import discord
 2from discord.ext import commands
 3
 4from antispam import AntiSpamHandler
 5from antispam.caches import MongoCache
 6
 7bot = commands.Bot(command_prefix="!", intents=discord.Intents.all())
 8bot.handler = AntiSpamHandler(bot)
 9
10my_cache = MongoCache(bot.handler, "Mongo connection url")
11bot.handler.set_cache(my_cache)

Once a cache is registered like so, there is nothing else you need to do. The package will simply use that caching mechanism.

Also note, AntiSpamHandler will call antispam.abc.Cache.initialize() before any cache operations are undertaken.