Fox-V3/leaver/leaver.py
bobloy f130c3e67f
Cogboard fixes (#37)
* Unneeded requirements

* Typo and While True

* Empty requirements

* audio tag

* Correct description, `audioset notify` alert, unneeded lavaplayer line

* unneeded requirements

* extra slash

* Add CPU / RAM / Disk warning

* Unneeded requirements

* Proper coglint requirements

* Default for `"Hi {}, I'm Dad"` set to enabled

* unneeded requirements

* Add list command, fix no_pm to guild_only

* Remove some comments and rename variable

* Fix to bugs

* unneeded requirements

* unneeded requirements

* remove pass_context legacy code

* More accurate instructions

* fix custom emojis

* less comments

* Unneeded requirements

* Unneeded requirements

* proper description

* Fix description wrap

* Unneeded requirements

* Unneeded requirements

* Missing await

* Info updates

* `await ctx.embed_requested`

* no requirements necessary

* markdown

* missing help

* Auto_help handles it

* Leaverset channel description

* Embeds and optional nicknames

* text clarification

* test alternative path

* Gotta upload the fixes

* more fix

* another test

* Steal skyrim

* Undo skyrim test

* Forgot await

* Use .json files, proper init to use files, move cooldown to seed
2018-10-26 15:50:24 -04:00

50 lines
1.6 KiB
Python

import discord
from redbot.core import Config, checks, commands
from redbot.core.bot import Red
from redbot.core.commands import Context
from typing import Any
Cog: Any = getattr(commands, "Cog", object)
class Leaver(Cog):
"""
Creates a goodbye message when people leave
"""
def __init__(self, bot: Red):
self.bot = bot
self.config = Config.get_conf(self, identifier=9811198108111121, force_registration=True)
default_guild = {"channel": ""}
self.config.register_guild(**default_guild)
@commands.group(aliases=["setleaver"])
@checks.mod_or_permissions(administrator=True)
async def leaverset(self, ctx):
"""Adjust leaver settings"""
if ctx.invoked_subcommand is None:
pass
@leaverset.command()
async def channel(self, ctx: Context):
"""Choose the channel to send leave messages to"""
guild = ctx.guild
await self.config.guild(guild).channel.set(ctx.channel.id)
await ctx.send("Channel set to " + ctx.channel.name)
async def on_member_remove(self, member: discord.Member):
guild = member.guild
channel = await self.config.guild(guild).channel()
if channel != "":
channel = guild.get_channel(channel)
out = "{}{} has left the server".format(member, member.nick if member.nick is not None else "")
if await self.bot.embed_requested(channel, member):
await channel.send(embed=discord.Embed(description=out, color=self.bot.color))
else:
await channel.send(out)
else:
pass