Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

ctx.message.channel.edit not running everytime command is called

So, I currently have this command to change the title of a channel in discord with discord py. The command works a few times in each channel then subsequently breaks on a per channel basis (or finishes the command around 6+min later).

import api
import discord
from discord.ext import commands

client = discord.Client()
client = commands.Bot(command_prefix=["pp.", "Pp.", "PP.", "pP."])
@client.command(pass_context=True)
async def progress_update(ctx, new_emoji):
    if ctx.message.channel.name[0] not in ["🟢", "🔵", "🟡", "🔴"]:
        await ctx.send("That is not a valid channel to run **progress_update** in.\nPlease run this command in a challenge channel")
        return

    if new_emoji not in ["🟢", "🔵", "🟡", "🔴"]:
        await ctx.send("That is not a valid emoji.\nPlease use one of the following: 🟢, 🔵, 🟡, 🔴")
        return

    new_name = new_emoji + ctx.message.channel.name[1:]
    temp = await ctx.message.channel.edit(name=new_name)
    await ctx.send("Progress updated!")

client.run(api.api)

I am stumped as to what the problem can be. It only appears to be happening on the ctx.message.channel.edit command, as I can still view the error messages (in the not it statements) if I type the command wrong.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You are most likely hitting ratelimits. You can only change the name or the topic of a channel twice per 10 minutes. Thankfully discord.py handles ratelimits by itself and you don’t get an error. You can also see this if you enable logging.

though, do be aware, your console is going to get spammed with every request your bot makes to discord API, you can set a more specific logging to mitigate this. Just a heads up.

Read more about setting up logging here

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading