Vote Server Reference
Creating the webhook server
Example:
from discord.ext import commands
from toppy import server
bot = commands.Bot("!")
bot.webhook_server = bot.loop.run_until_complete(server.create_server(
bot,
"0.0.0.0",
8080,
"/vote",
"super cool auth secret"
))
bot.run("...")
bot.webhook_server.cancel() # closes the server. Not really needed when the program is quitting, but oh well.
The create server function
- async toppy.create_server(bot, *, host: str = '0.0.0.0', port: int = 8080, path: str = '/', auth: Optional[str] = None, disable_warnings: bool = False) Task
Creates a vote webhook server.
This will listen for webhooks on <host>:<port>[/<path>].
MAKE SURE YOUR PORT IS FORWARDED AND THAT YOUR AUTH+PATH IS THE SAME AS THAT ON TOP.GG!
- Parameters
bot (
discord.Client) – Your bot instancehost (
str) – The host to run this on. Usually, it’s fine to leave this default.port (
int) – The port to listen to. Make sure it’s forwarded. This defaults to 8080.path (
str) – The bit after your IP/domain. Defaults to /.auth (Optional[
str]) – Your authorization you set on your top.gg bot settings. Please don’t leave this blank. Please.disable_warnings (
bool) – If True, this will disable any sort of warnings that may arise from the web server.
- Returns
A task containing the background wrap for running the server. You’re responsible for cleanup.
- Return type
Vote types
The following vote types may be passed to the event on_vote:
- class toppy.ServerVote(data: dict, *, state=None)
Represents a vote for a server listing
- property guild: Union[Guild, Object]
Returns the guild that was voted on.
Warning
similar to
SharedVote.user, this function will returndiscord.Objectif the internal cache lookup returns nothing.- Returns
- property user
Returns the user who voted.
Warning
If you don’t have the member cache, or members intent, then this function will always return
discord.Object, as that is the default when the get_user call fails.- Returns
- class toppy.BotVote(data: dict, *, state=None)
Represents a vote for a Bot listing
- Attributes:
- property bot: Union[User, Object]
The resolved bot user for this vote. This is, hopefully, always your current bot.
Warning
If the internal lookup fails, this returns a
discord.Objectby default.- Returns
- property user
Returns the user who voted.
Warning
If you don’t have the member cache, or members intent, then this function will always return
discord.Object, as that is the default when the get_user call fails.- Returns
Vote Event Reference
- on_vote(vote: Union[BotVote, ServerVote]):
Dispatched whenever there is a vote. Be sure to check the vote type and class.