0

Basically, I've been trying to run this code on repl.it but it just isn't working. I've tried the nest.asyncio and bot.process.commands fixes but they won't work. Basically the bot.event functions work perfectly fine, but the bot.command() won't work. I included an error inside the function so that it would show when the function was called, but it does't call. Here's my code

import discord,os
from discord.ext import commands
import nest_asyncio
import datetime

#Global vars
token = os.getenv("bot_token")
online_message = os.getenv("msg")
bot_name = "My First Bot"
cmd_prefix = "|"
mod_role = "Mod Role Name"
bot = commands.Bot(command_prefix = '-')
bot.remove_command('help')
counter = 0
nest_asyncio.apply()
test_area = bot.get_channel(id=937782074709004309)


# basically triggers (events) that will cause something to happen
@bot.command()
async def ping(ctx):
  await ctx.send(f'Pong! {round(bot.latency * 1000)}ms')
  hi

  
@bot.event
async def on_message(message):
    global counter
    
    if message.author == bot.user:
        return

    if message.content.startswith('testin'):
        await message.channel.send('hello')
        

    if message.author.id == 583469853126426643 and message.content == (
            'do I have a god complex?'):
        await message.channel.send('no')
        

    if 'kill' in message.content:
      await message.channel.send("please don't murder me")
      
    
    if message.content.startswith("$"):
      
      counter += 1
      await message.channel.send("ya'll have been dumb "+ str(counter) + " times")
      

    if message.content.startswith("!"):

      counter += 1
      await message.channel.send("ya'll have been dumb "+ str(counter) + " times")

    if message.content.startswith('off'):
      exit()
      return
    bot.process_commands(message)
    nest_asyncio.apply()

@bot.event
async def on_ready():
  await bot.get_channel(id=937782074709004309).send(online_message)
  nest_asyncio.apply()

      

bot.run(token)

I've tried every solution I can find, so discord python users with more knowledge plz help

Mekaeel Malik
  • 61
  • 1
  • 5
  • You can't have `client` and `bot` defined. Simply remove your `client` definition. – Dominik Feb 07 '22 at 22:30
  • 2
    `bot.process_commands` is a coroutine, it's supposed to be awaited. – Łukasz Kwieciński Feb 07 '22 at 22:56
  • @Dominik While there certainly isn't any reason to define client and bot, it isn't the issue here. Plus it's not true that you _can't_ have both defined. – TheFungusAmongUs Feb 07 '22 at 23:00
  • @Dominik Yeah I just forgot to take it out when trying some other fixes – Mekaeel Malik Feb 08 '22 at 00:28
  • @ŁukaszKwieciński THANKS!!!! I was having a really hard time with this – Mekaeel Malik Feb 08 '22 at 00:29
  • @TheFungusAmongUs You can write it down, but it will interfere with `client` or `bot`, in whatever way you want to see it. – Dominik Feb 08 '22 at 00:30
  • @Dominik I know I'm being pointlessly pedantic and I apologise for that, but I just don't think it's right to say you _can't_ have both defined. I've seen a handful of posts even on stackoverflow regarding the issue of how to run multiple clients in one script. The two only interfere with each other if you misuse them. – TheFungusAmongUs Feb 08 '22 at 03:44

0 Answers0