-
-
Notifications
You must be signed in to change notification settings - Fork 460
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
Fix extensions in discord.Bot #838
Conversation
Signed-off-by: plun1331 <plun1331@gmail.com>
Signed-off-by: plun1331 <plun1331@gmail.com>
This PR still causes the same error with reloading extensions that I mentioned in the original revert PR (#829):
|
I wasn't experiencing this during testing, I'll look into it more tomorrow. Do you have a code sample for reproducing? |
Sure: import discord
from discord.commands import slash_command
from discord.ext import commands
class Temptests(commands.Cog):
def __init__(self, bot):
self.bot = bot
@slash_command(name="test838")
async def test838(self, ctx: discord.ApplicationContext):
"""Test for #838"""
await ctx.respond("Test for #838")
def setup(bot):
bot.add_cog(Temptests(bot)) Running this command causes the error: bot.reload_extension("extensions.temptests") # or wherever the extension is located |
I can't seem to reproduce this, although I am on Python 3.9 instead of 3.10 |
I've tried with 3.9 as well and can reproduce the error there too. |
Do you have a sample of the code in the bot's main file? |
|
Head branch was pushed to by a user without write access
Head branch was pushed to by a user without write access
I found a way to reliably reproduce the To trigger the error, just run /test838. Extension 1 (extensions/ext_temptests.py): import discord
from discord.commands import slash_command, SlashCommandGroup
from discord.ext import commands
class Temptests(commands.Cog):
def __init__(self, bot):
self.bot = bot
gtest = SlashCommandGroup("gtest", "gtest")
@gtest.command(name="dothing", description="gtest")
async def gtest_dothing(self, ctx: discord.ApplicationContext):
await ctx.respond("gtest_dothing")
@slash_command(name="test838", guild_ids=[...])
async def test838(self, ctx: discord.ApplicationContext):
"""Test for #838"""
await ctx.respond("Test for #838")
self.bot.reload_extension("extensions.ext_temptests2")
def setup(bot):
bot.add_cog(Temptests(bot)) Extension 2 (extensions/ext_temptests2.py): from discord.ext import commands
from discord.commands import slash_command
class Temptests2(commands.Cog):
def __init__(self, bot):
self.bot = bot
@slash_command()
async def testing838(self, ctx):
await ctx.respond("Test for #838")
self.bot.reload_extension("extensions.ext_temptests")
def setup(bot):
bot.add_cog(Temptests2(bot)) Main bot code: from os import listdir
from os.path import isfile, join
from discord.ext import commands
import discord
intents = discord.Intents.all()
bot = commands.Bot(command_prefix=[">", "/"], intents=intents, owner_ids=[...])
ext_list = [f for f in listdir("extensions/") if isfile(join("extensions/", f))]
extensions = [item.replace(".py", "") for item in ext_list]
for extension in extensions:
bot.load_extension(f"extensions.{extension}")
bot.run("token here") |
The slash command in the second extension appears to have bad indentation |
Good catch, updated to clarify that command registration isn't affected. The |
I believe I fixed the module AttributeError, however I may have uncovered another issue. When testing I was printing out {
None: <discord.commands.SlashCommand name=test838>,
'936472246011183114': <discord.commands.SlashCommandGroup name=gtest>,
'936472246011183115': <discord.commands.SlashCommand name=test838>,
'936472246011183116': <discord.commands.SlashCommand name=testing838>
} Unsure why this happened, I don't believe it's related to my PR though. Should most likely check if this can be reproduced on master. |
@plun1331 state |
I don't believe there are any more issues |
Summary
Fixes: #816
Originally #817, uses a fix from #826
I searched around in the issues tab for other problems people found with this and only found #825, if there are others please let me know.
This was tested with:
Checklist
type: ignore
comments were used, a comment is also left explaining why