Raizel
Raizel

Reputation: 11

the commands of my discord bot is not working except 1

import discord
import os
import requests
import json
import random
from random import randint
from replit import db
from discord.ext import commands


client = discord.Client()

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

@client.event
async def on_ready():
  print(f'{client.user.name} működik!')   
  await client.change_presence(activity=discord.Game(name='egy bot vagyok'))

@client.event
async def on_member_join(member):
    await member.create_dm()   
    await member.dm_channel.send(
        f' {member.name}, itt van!'
    )


@bot.command()
async def test(ctx, arg):
    await ctx.send(arg)
    print(f'haha')

@client.event
async def on_message(message):

    if message.author == client.user:
        return

    if message.content.startswith('ping'):
        await message.channel.send("pong")

    if message.content.startswith("shrug"):
        await message.channel.send('¯\_(ツ)_/¯')

@client.event
async def on_message(message):
  if message.author == client.user:
    return

  if message.content.startswith('.pic'):
    await message.channel.send(file=discord.File('combo-0.png'))


token = os.environ.get("secret")
client.run(token)

im a beginner in discord bot programming this is my whole code for my discord bot and all of the commands are not working except one

te .pic command

all of the commands worked until now and i dont know why they dont work

if i would get some help i would be happy :D (sorry for my bad english, english isnt my first language)

Upvotes: 1

Views: 144

Answers (2)

A random coder
A random coder

Reputation: 473

You can't mix up the discord.Client() and commands.Bot clients like this.

commands.Bot is a subclass of discord.Client, so you should be able to do everything that you could do with discord.Client() with commands.Bot()

bot = commands.Bot('!')
@bot.event
async def on_ready():
    print('ready')

@bot.command()
async def ping(ctx):
    await ctx.send('pong')

For help with the rewrite discord.ext.commands, there are a butt ton of tutorials on the internet.

Upvotes: 0

Łukasz Kwieciński
Łukasz Kwieciński

Reputation: 15689

You cannot have multiple on_message events, only the last one will be registered. You have to combine them into one

@client.event
async def on_message(message):
    if message.author == client.user:
        return

    if message.content.startswith('ping'):
        await message.channel.send("pong")

    if message.content.startswith("shrug"):
        await message.channel.send('¯\_(ツ)_/¯')

    if message.content.startswith('.pic'):
        await message.channel.send(file=discord.File('combo-0.png'))

Upvotes: 1

Related Questions