1
votes

I'm having a lot of trouble with discord.py rewrite and its migration. I looked at the migrating to v1.0 site and it said to put in message.delete() and so I did but I realised that wasn't working so I put in ctx aswell. But that put it to an error. There are two commands with this error at the moment.

I have already tried putting the message into a variable.

@client.command()
async def clear(ctx, amount=100):
    message = ctx.message
    channel = ctx.message.channel
    messages = []
    await ctx.channel.purge(limit=int(amount+1))
    mymessage = await channel.send('Messages deleted')
    await ctx.message.delete(mymessage)

@client.command()
async def verify(ctx, *, arg):
    print(ctx.message.channel.id)
    print(ctx.message.author)
    if ctx.channel.id == 521645091098722305:
        role = await ctx.guild.create_role(name=arg)
        await ctx.message.author.add_roles(role)
        mymessage = await ctx.send('Done! Welcome!')
        await ctx.message.delete(mymessage)
        await ctx.message.delete(ctx.message)

I expected the output to delete the message. For the clear one it deletes it and then gives it back. for the verify one it just keeps it as the same and shows the error: raise CommandInvokeError(exc) from exc discord.ext.commands.errors.CommandInvokeError: Command raised an exception: TypeError: delete() takes 1 positional argument but 2 were given

Also my role giving verify sometimes goes 3 times. I have went into task manager and killed all of the python too but it still did that. Once when I was clearing it said Done! Welcome as well. If you can answer this question as well, I would be pleased! Thank you in advance.

2

2 Answers

1
votes

Message.delete doesn't take any arguments. It's a method that you call on the message you want to delete. Change

await ctx.message.delete(mymessage)
await ctx.message.delete(ctx.message)

to

await mymessage.delete()
await ctx.message.delete()
0
votes
@client.command(pass_context=True)
async def delete(ctx, arg):
    arg1 = int(arg) + 1
    await client.purge_from(ctx.message.channel, limit=arg1)

!delete 10 - delete the last 10 posts