bennediction
bennediction

Reputation: 11

discord.py bot won't respond to commands

I'm having a problem where my bot won't respond to commands. here's my code:

import os
import discord
from discord.ext import commands
from discord.ext.commands import Bot
import random

client = discord.Client()

bot = commands.Bot(command_prefix='!')

@client.event #server + member list
async def on_ready():
    guild = discord.utils.get(client.guilds, name=GUILD)
    print(
        f'{client.user} is connected to the following guild:\n'
        f'{guild.name}(id: {guild.id})\n'
    )

    members = '\n - '.join([member.name for member in guild.members])
    print(f'Guild Members:\n - {members}')

@bot.command() 
async def test(ctx, arg):
    await ctx.send(arg)

client.run(TOKEN)

I have other client events for the bot in the code that have worked, such as reacting to messages and replying to messages. My above code hasn't been working even after I've commented out all of the other comments. while running the program, I've typed !test arg in my discord channel, but have only gotten the programmed reaction from my bot when it wasn't commented out.

Upvotes: 1

Views: 996

Answers (1)

Patrick Haugh
Patrick Haugh

Reputation: 61062

You can only have one Bot/Client running at a time. I would use Bot because the Bot class is a subclass of the Client class, so it can do everything it's parent can do.

from discord.ext import commands
import discord.utils

bot = commands.Bot(command_prefix='!')

@bot.event #server + member list
async def on_ready():
    guild = discord.utils.get(bot.guilds, name=GUILD)
    print(
        f'{client.user} is connected to the following guild:\n'
        f'{guild.name}(id: {guild.id})\n'
    )

    members = '\n - '.join([member.name for member in guild.members])
    print(f'Guild Members:\n - {members}')

@bot.command() 
async def test(ctx, arg):
    await ctx.send(arg)

bot.run(TOKEN)

Upvotes: 2

Related Questions