1

Okay so this is my code:

@client.command(aliases=['d'], pass_context=True)
async def decrypt(ctx, arg, member=discord.Member):
    key = b'xxxxxx'
    f = Fernet(key)
    decrypted = f.decrypt(arg)
    channel = await member.create_dm()
    await channel.send(f'Decrypted message: {decrypted}')

I insert a string after ctx, and it says TypeError: token must be bytes. My arg is this (which is a byte, right?): b'gAAAAABgx22pwwjUHUA7KqV8jmZrXvocfC3VrHS_QrGCfCaEyj6f7cG1_K3NtbkADYiR4l8fq-DiqYJJk2k8n0jBUhDYsH2kNA=='

1 Answers1

0

First of all, pass_context is deprecated. Second, no need to use create_dm; members are messageables, so you can do member.send. Third, discord.py interprets all arguments as strings by default. You'll need to use typehints (speaking of which, = is used to assign default values, not argument types). And fourth, this will send Decrypted message: b'meetmeatthepetstore', not Decrypted message: meetmeatthepetstore, so you'll want to decode the result. Here's the result:

@client.command(aliases=['d'])
async def decrypt(ctx, arg: bytes, member: discord.Member):
    key = b'mycoolkey'
    f = Fernet(key)
    decrypted = f.decrypt(arg).decode('utf_8')
    await member.send(f'Decrypted message: {decrypted}')
Makonede
  • 442
  • 1
  • 6
  • 13