My Bot is not Responding in Discord even though it is logged in

I get this in my consule:

INFO:root:We have logged in as Artsy Bot#6020
INFO:root:Message received:  in channel: general
import os
import random
import discord
import logging

# Set up logging
logging.basicConfig(level=logging.INFO)

# Load tokens from environment variables
try:
    BOT_TOKEN = os.environ['TOKEN']
except KeyError:
    logging.error("Error: Token environment variable not set")
    exit(1)

# Load data from files
def load_data(file_name):
    try:
        with open(file_name) as file:
            return file.readlines()
    except FileNotFoundError:
        logging.error(f"Error: {file_name} not found")
        return []

# Initialize Discord client
intents = discord.Intents.default()
client = discord.Client(intents=intents)

# Command prefixes
COMMAND_PREFIX = "!"

# Load data
Colors = load_data('Colors.txt')
Media = load_data('Media.txt')
Themes = load_data('Theme.txt')
Style = load_data('Style.txt')

# Command handling
async def handle_command(message, command, options):
    logging.info(f'{command} command received')
    response = random.choice(options)
    logging.info(f'Response: {response}')

    try:
        await message.channel.send(response)
        logging.info('Response sent successfully!')
    except Exception as e:
        logging.error(f"Error sending response: {e}")

# Event handling
@client.event
async def on_ready():
    logging.info(f'We have logged in as {client.user}')

@client.event
async def on_message(message):
    logging.info(f'Message received: {message.content} in channel: {message.channel.name}')

    if message.author == client.user:
        return

    if message.content.startswith(COMMAND_PREFIX):
        command, *args = message.content[len(COMMAND_PREFIX):].split()

        if command == 'Colors':
            await handle_command(message, 'Colors', Colors)
        elif command == 'Theme':
          await handle_command(message, 'Theme', Themes)
        elif command == 'Media':
            await handle_command(message, 'Media', Media)
        elif command == 'Style':
            await handle_command(message, 'Style', Style)

# Run the bot
client.run(BOT_TOKEN)

did you create a command to use?

all it is saying, is that it recived the message, not responded to it

I used # Command prefixes
COMMAND_PREFIX = “!”

Yes, and I want to figure out why it is not responding.

Can you share the link to your repl?

2 Likes

https://replit.com/@YoloDisorder/Artsy-Bot

I don’t really use discord.Client. You can try using commands.Bot like this:

from discord.ext import commands
import discord

bot = commands.Bot(
    command_prefix=';',
    help_command=None,
    description='',
    intents=discord.Intents.all(),
    case_insensitive=True,
    allowed_mentions=discord.AllowedMentions.all(),
    strip_after_prefix=True
)

Shouldn’t the Intents include the message? like intents.messages = True

1 Like

that is also the thing, if it doesn’t have right perms, it wont type

usually it is intents.message_content = True.
Thats what works for me.

make sure that intents is defined in the bot define thing too. so:

bot = commands.Bot(command_prefix=‘?’, intents=intents) (Command Prefix can be whatever you want it to be)

1 Like

Thank you, I can’t believe I missed this. It worked Great!

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.