Home > database >  Discord Python not responding to my messages
Discord Python not responding to my messages

Time:12-19

So i made A discord bot With message_content intent Here is the code

#I added the token but removed it so no one can mess with my bot
token = ''
import discord
import random
channelid = '1054033441538195456'
first = """
:green_circle::green_circle:red_circle::red_circle::red_circle:
:green_circle::green_circle:red_circle::red_circle::red_circle:
:red_circle::red_circle::red_circle::red_circle::red_circle:
:red_circle::red_circle::red_circle::red_circle::red_circle:
:red_circle::red_circle::red_circle::red_circle::red_circle:
"""
second = """
:red_circle::red_circle::red_circle:green_circle::green_circle:
:red_circle::red_circle::red_circle:green_circle::green_circle:
:red_circle::red_circle::red_circle::red_circle::red_circle:
:red_circle::red_circle::red_circle::red_circle::red_circle:
:red_circle::red_circle::red_circle::red_circle::red_circle:
"""

intents = discord.Intents.default()


client = discord.Client(intents=discord.Intents())

@client.event
async def on_ready():
    print(f'Kine tag is {client.user}')

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

    if message.content.startswith('$predict'):
        suas = random.randrange(0,3)
        if suas == '1':
           await message.channel.send("Kine!\n" first)
        if suas == '2':
           await message.channel.send("Kine!\n" second)
        
client.run(token)

When i try its online but doesn't respond to my messages To respond to my messages but it doesnt Im still new to the discord.py development

CodePudding user response:

This I assume:

intents = discord.Intents.default()
intents.message_content = True
client = discord.Client(intents=intents)
...

CodePudding user response:

You are testing if an integer suas is equal to a string. Which will never be.

>>> 1 == "1"
False

It is always good to implement some sort of failsafe information, as long as you are not 110% confident that your code works.

        suas = random.randrange(0,3)
        if suas == 1:
           await message.channel.send("Kine!\n" first)
        elif suas == 2:
           await message.channel.send("Kine!\n" second)
        else:
            print("invalid event")

  • Related