Basically what I want to do Is make a command that goes a bit like this:
User: >unpin 10
Bot unpins said amount and returns: Unpinned amount in #channel
So far all I've done so far is:
@Bot.command()
async def unpin(ctx, amount = 0):
await ctx.message.delete()
channel = ctx.channel
x = 0
amount = int(amount)
if amount == 0:
await ctx.send("How many messages do you want to unpin, max is 50.")
if amount > 50:
await ctx.send("Maximum amount is 50")
else:
pins = await channel.pins()
while x <= amount:
for message in pins:
await message.unpin()
x+=1
await ctx.send(f"Unpinned {x} messages from #{channel}")
The problem here is that the bot unpins every message instead of the given amount. How could I change this to make it unpin a given amount?
Make it more pythonic. Instead of using while x <= amount: ... x += 1
, use a for loop. Also, don't double-loop. The second loop loops through all of the pins and un-pins all of them. An example of a better system might be as follows:
...
else:
for i in range(amount):
pins = await channel.pins()
await pins[-1].unpin()
await ctx.send(f"Unpinned {x} messages from #{channel}")
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments