简体   繁体   中英

Discord.py : How to keep \n in args when sending messages

I'm trying to create a command that formats your code on Discord with a given language,

by sending the formatted string:

f"```{language}\n{code}\n```"

The function prototype is :

def format(ctx, language, *code)

And I'm typing on Discord for example :

!format c int function(int x)
{
  return x;
}

But when I tried to print out the code arg, there is no \\n in the list and the bot message is on a single line.

I also tried with quotation marks around my message, and this worked for keeping \\n but if my code contains another quotation mark it ends the code arg, and throws an error for the remaining part.

Is there a way to get the complete message including newlines?

You need to change your OS sed option so you could get newline or tab characters back.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM