Skip to content Skip to sidebar Skip to footer

Discord.py Bot Stops Responding After I Add A New Block Of Code

im new to python and discord.py, this is a repost with updated details and without the block of code that was hard to understand. I have not found an answer to this problem online

Solution 1:

Blocking code

It appears that the synchronous code in the on_ready event is what is hanging the bot; waiting for input from the console halts any other code from running, including reacting to commands.

The only way to fix this is to design your announcement command in a different way that doesn't involve using your console, such as having it be a command for your bot.

Sidenote about discord.Client()

Since you're using the lower-level API (discord.Client), you may find it more difficult to develop new commands for your bot. I would recommend using the bot commands framework (discord.ext.commands) that discord.py comes packaged with. The pitch is in the link so instead, here's an example using the framework with your boop command:

import time
import discord
from discord.ext import commands

prefix = 'c!'
TOKEN = ''

client = commands.Bot(command_prefix=prefix)

@client.eventasyncdefon_ready():
    print('Logged in as', client.user.name)

@client.command(name='boop')asyncdefclient_boop(ctx, user: discord.User):
    """Boops a user.
Accepted inputs are: ID, mention, name#discrim, or name
Example: c!boop thegamecracks"""await user.send('**Boop!**')
    await ctx.channel.send("Booped " + user.name)

    current_time = time.strftime("%H:%M:%S", time.localtime())
    log_channel = client.get_channel(759798825161326593)
    LogMsg = '`{}` {} used command in {} `{}`'.format(
        current_time,
        ctx.author.name,
        ctx.channel.name,
        ctx.message.content
    )
    await log_channel.send(LogMsg)

client.run(TOKEN)

Post a Comment for "Discord.py Bot Stops Responding After I Add A New Block Of Code"