Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to discord.py 2.0.1, add slash command functionality #93

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,6 @@ export/
*.pyc

#backup
backup/
backup/

.env
10 changes: 5 additions & 5 deletions cogs/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ async def cog_command_error(self, ctx, error):
else:
logger.warning(error)

@commands.command(aliases=['r'])
@commands.hybrid_command(aliases=['r'], description="Reloads cogs")
async def reload(self, ctx, *, cog):
if cog == 'c':
cog = 'poll_controls'
Expand All @@ -31,7 +31,7 @@ async def reload(self, ctx, *, cog):

reply = ''
try:
self.bot.reload_extension('cogs.'+cog)
await self.bot.reload_extension('cogs.'+cog)
reply = f'Extension "cogs.{cog}" successfully reloaded.'
except commands.ExtensionNotFound:
reply = f'Extension "cogs.{cog}" not found.'
Expand All @@ -42,7 +42,7 @@ async def reload(self, ctx, *, cog):
except commands.ExtensionNotLoaded:
reply = f'Extension "cogs.{cog}" is not loaded... trying to load it. '
try:
self.bot.load_extension('cogs.'+cog)
await self.bot.load_extension('cogs.'+cog)
except commands.ExtensionAlreadyLoaded:
reply += f'Could not load or reload extension since it is already loaded...'
except commands.ExtensionNotFound:
Expand All @@ -54,7 +54,7 @@ async def reload(self, ctx, *, cog):
await ctx.send(reply)


def setup(bot):
async def setup(bot):
global logger
logger = logging.getLogger('discord')
bot.add_cog(Admin(bot))
await bot.add_cog(Admin(bot))
23 changes: 11 additions & 12 deletions cogs/config.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import logging
from discord.ext import commands
from discord import app_commands
from discord import Role

class Config(commands.Cog):
def __init__(self, bot):
self.bot = bot

@commands.command()
@commands.hybrid_command(name="prefix", description="""Set a custom prefix for the server.""")
@commands.has_permissions(manage_guild=True)
async def prefix(self, ctx, *, pre):
"""Set a custom prefix for the server."""
async def prefix(self, ctx, *, pre:str):
server = ctx.message.guild
if pre.endswith('\w'):
pre = pre[:-2]+' '
Expand All @@ -25,10 +26,9 @@ async def prefix(self, ctx, *, pre):
self.bot.pre[str(server.id)] = str(pre)
await ctx.send(msg)

@commands.command()
@commands.hybrid_command(name="adminrole", description="Set or show the Admin Role. Members with this role can create polls and manage ALL polls.")
@commands.has_permissions(manage_guild=True)
async def adminrole(self, ctx, *, role=None):
"""Set or show the Admin Role. Members with this role can create polls and manage ALL polls. Parameter: <role> (optional)"""
async def adminrole(self, ctx, *, role: Role = None):
server = ctx.message.guild

if not role:
Expand All @@ -47,11 +47,10 @@ async def adminrole(self, ctx, *, role=None):
else:
await ctx.send(f'Server role `{role}` not found.')

@commands.command()
@commands.hybrid_command(name="userrole", description="Set or show the User Role. Members with this role can create polls and manage their own polls.")
@commands.has_permissions(manage_guild=True)
async def userrole(self, ctx, *, role=None):
"""Set or show the User Role. Members with this role can create polls and manage their own polls.
Parameter: <role> (optional)"""
async def userrole(self, ctx, *, role: Role=None):

server = ctx.message.guild

if not role:
Expand All @@ -71,7 +70,7 @@ async def userrole(self, ctx, *, role=None):
await ctx.send(f'Server role `{role}` not found.')


def setup(bot):
async def setup(bot):
global logger
logger = logging.getLogger('discord')
bot.add_cog(Config(bot))
await bot.add_cog(Config(bot))
4 changes: 2 additions & 2 deletions cogs/db_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ async def update_stats(self):
logger.exception('Failed to post server count\n{}: {}'.format(type(e).__name__, e))


def setup(bot):
async def setup(bot):
global logger
logger = logging.getLogger('discord')
bot.add_cog(DiscordBotsOrgAPI(bot))
await bot.add_cog(DiscordBotsOrgAPI(bot))
11 changes: 6 additions & 5 deletions cogs/eval.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@
from contextlib import redirect_stdout

from discord.ext import commands
from discord import app_commands


class Eval(commands.Cog):
def __init__(self, bot):
self.bot = bot

@commands.command()
@commands.hybrid_command(name="eval", description="""Evaluates a code""")
@commands.is_owner()
async def evall(self, ctx, *, body: str):
self.bot.eval_wait = True
Expand All @@ -29,10 +30,10 @@ async def evall(self, ctx, *, body: str):
finally:
self.bot.eval_wait = False

@commands.command(hidden=True, name='eval')
@commands.hybrid_command(hidden=True, name='eval', description="""Evaluates a code""")
@commands.is_owner()
async def _eval(self, ctx, *, body: str):
"""Evaluates a code"""


env = {
'bot': self.bot,
Expand Down Expand Up @@ -78,5 +79,5 @@ async def _eval(self, ctx, *, body: str):
await ctx.send(f'```py\n{value}{ret}\n```')


def setup(bot):
bot.add_cog(Eval(bot))
async def setup(bot):
await bot.add_cog(Eval(bot))
12 changes: 7 additions & 5 deletions cogs/help.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import discord
from discord.ext import commands
from discord import app_commands

from essentials.multi_server import get_server_pre, ask_for_server
from essentials.settings import SETTINGS
Expand Down Expand Up @@ -43,7 +44,6 @@ def check(rct, usr):
return reaction

def get_help_embed(self, page, pre):

title = f' Pollmaster Help - React with an emoji to learn more about a topic!'
embed = discord.Embed(title='', description='', colour=SETTINGS.color)
embed.set_author(name=title, icon_url=SETTINGS.author_icon)
Expand Down Expand Up @@ -235,8 +235,10 @@ def get_help_embed(self, page, pre):

return embed

@commands.command()
async def help(self, ctx):
# @commands.hybrid_command(name="pmhelp",description="Display commands")

@commands.hybrid_command(name="help", description="Display commands")
async def pmhelp(self, ctx):
server = await ask_for_server(self.bot, ctx.message)
if not server:
return
Expand Down Expand Up @@ -365,7 +367,7 @@ async def on_message(self, message):
await channel.send(status_msg)


def setup(bot):
async def setup(bot):
global logger
logger = logging.getLogger('discord')
bot.add_cog(Help(bot))
await bot.add_cog(Help(bot))
Loading