I am trying to add cogs to my bot but It gives error(in repl.it):
this works without cogs
I also deleted the last discord.py(1.7.3)
and tried reinstalling the discord.py 2.0
this is on replit.com
that db and that secrets are replit specials also that doesnt effect the code in any ways
Traceback (most recent call last):
File "/home/runner/Dmoame/venv/lib/python3.8/site-packages/discord/ext/commands/bot.py", line 934, in _load_from_module_spec
spec.loader.exec_module(lib) # type: ignore
File "<frozen importlib._bootstrap_external>", line 843, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/home/runner/Dmoame/cogs/Ticket.py", line 4, in <module>
class Tickets(commands.Cog):
File "/home/runner/Dmoame/cogs/Ticket.py", line 9, in Tickets
async def hello(ctx):
File "/home/runner/Dmoame/venv/lib/python3.8/site-packages/discord/ext/commands/core.py", line 1748, in decorator
return cls(func, name=name, **attrs)
File "/home/runner/Dmoame/venv/lib/python3.8/site-packages/discord/ext/commands/core.py", line 361, in __init__
self.callback = func
File "/home/runner/Dmoame/venv/lib/python3.8/site-packages/discord/ext/commands/core.py", line 470, in callback
self.params: Dict[str, Parameter] = get_signature_parameters(function, globalns)
File "/home/runner/Dmoame/venv/lib/python3.8/site-packages/discord/ext/commands/core.py", line 128, in get_signature_parameters
raise TypeError(f'Command signature requires at least {required_params - 1} parameter(s)')
TypeError: Command signature requires at least 1 parameter(s)
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "main.py", line 31, in <module>
asyncio.run(main())
File "/nix/store/2vm88xw7513h9pyjyafw32cps51b0ia1-python3-3.8.12/lib/python3.8/asyncio/runners.py", line 44, in run
return loop.run_until_complete(main)
File "/nix/store/2vm88xw7513h9pyjyafw32cps51b0ia1-python3-3.8.12/lib/python3.8/asyncio/base_events.py", line 616, in run_until_complete
return future.result()
File "main.py", line 28, in main
await load_extensions()
File "main.py", line 19, in load_extensions
await bot.load_extension(f"cogs.{filename[:-3]}")
File "/home/runner/Dmoame/venv/lib/python3.8/site-packages/discord/ext/commands/bot.py", line 1012, in load_extension
await self._load_from_module_spec(spec, name)
File "/home/runner/Dmoame/venv/lib/python3.8/site-packages/discord/ext/commands/bot.py", line 937, in _load_from_module_spec
raise errors.ExtensionFailed(key, e) from e
discord.ext.commands.errors.ExtensionFailed: Extension 'cogs.Ticket' raised an error: TypeError: Command signature requires at least 1 parameter(s)
main.py:
import os
from replit import db
import asyncio
import discord
from discord.ext import commands
inte = discord.Intents.all()
bot = commands.Bot(command_prefix=".", intents =inte)
try:
print(db["servers"])
except:
db["servers"] = {}
async def load_extensions():
for filename in os.listdir("./cogs"):
if filename.endswith(".py"):
await bot.load_extension(f"cogs.{filename[:-3]}")
Token = os.environ['Token']
async def main():
async with bot:
await load_extensions()
await bot.start(Token)
asyncio.run(main())
Ticket.py in cogs folder
import discord
from discord.ext import commands
from replit import db
class Tickets(commands.Cog):
def __init__(self, bot):
self.bot = bot
@commands.command(name="ticket")
async def hello(ctx):
tks = discord.ui.Select(placeholder="Choose Your Help!",options=[discord.SelectOption(label="Support", emoji="🗨", default=True), discord.SelectOption(label="Idea", emoji="ðŸ’")])
acbtn = discord.ui.Button(label="Create Ticket", style=discord.ButtonStyle.green, emoji="🎫")
async def choose(inter):
try:
count = db["servers"][f"{ctx.message.guild.id}"]["ticket_count"] + 1
except:
db["servers"][f"{ctx.message.guild.id}"] = {"ticket_count":0}
count = db["servers"][f"{ctx.message.guild.id}"]["ticket_count"] + 1
await inter.response.send_message(f"Ticket: {tks.values[0]}-{count}", ephemeral=True)
db["servers"][f"{ctx.message.guild.id}"]["ticket_count"] += 1
guild = ctx.message.guild
await guild.create_text_channel(f"ticket: {tks.values[0]}-{count}")
async def change(inte):
await inte.response.send_message(f"You changed the subject to {tks.values[0]}", ephemeral=True)
tks.callback = change
acbtn.callback = choose
vitks = discord.ui.View()
vitks.add_item(tks)
vitks.add_item(acbtn)
await ctx.send("Open A Ticket!", view=vitks)
async def setup(bot):
await bot.add_cog(Tickets(bot))
You also need to pass Self
to the function
So instead of
async def hello(ctx):
use async def hello(self, ctx):