I was able to load the extension just fine, but whenever I try it out on Discord as Qball/.Qball/_Qball, the bot won't answer.
Quokkabot.py (main)
import discord
import random
import os
from discord.ext import commands
client = commands.Bot(command_prefix = '.')
@client.command()
async def load(ctx, extension):
client.load_extension('.cogs.Quokkabot2')
@client.event
async def on_ready():
print('{0.user} JOINED THE PARTY!'.format(client))
client.run('token')
Quokkabot2.py (cog)
import discord
from discord.ext import commands
class Commands(commands.Cog):
def __init__(self, client):
self.client = client
@commands.command(aliases=['Qball, test'])
async def _Qball(ctx):
responses = [#answers]
await ctx.send(f'{random.choice(responses)}')
def setup(client):
client.add_command(Qball(client))
Commands on a cog should be defined as instance methods on that cog.
class Commands(commands.Cog):
def __init__(self, client):
self.client = client
@commands.command(aliases=['Qball, test'])
async def _Qball(self, ctx):
responses = [#answers]
await ctx.send(f'{random.choice(responses)}')
Then, in your main
client = commands.Bot(command_prefix = '.')
client.add_cog(Commands(client))
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.