我将如何在编译后立即将 pdfLaTeX 的 pdf 输出发送到不和谐频道?
How would I go about sending the pdf output of pdfLaTeX to a discord channel right after compiling it?
这是我到目前为止尝试过的方法,虽然它无法发送 pdf,但它只编译了提供给它的 TeX 代码。我是 python 的新手,所以如果我的问题的答案似乎很明显,请多多包涵。
import os
import discord
import subprocess
from discord.ext import commands
bot = commands.Bot(command_prefix=".")
allowed_IDs = [1234567890]
@bot.event
async def on_ready():
print("Bot is online")
@bot.command()
async def tex(ctx, *, code):
if ctx.author.id in allowed_IDs:
await subprocess.call(f"pdflatex -output-directory=tex -jobname={ctx.author.id} -interaction=nonstopmode -no-shell-escape tex/default.tex '\begin{{document}}{code}\end{{document}}'")
await ctx.send(file=discord.File(f"tex/{ctx.author.id}.pdf"))
else:
await ctx.send("You cannot use this command")
bot.run(os.getenv("TOKEN"))
根据@Łukasz Kwieciński 的建议,我从 subprocess.call
中删除了 await
,事实证明这就是我的代码未按预期工作的原因。非常感谢您的帮助。
这是我到目前为止尝试过的方法,虽然它无法发送 pdf,但它只编译了提供给它的 TeX 代码。我是 python 的新手,所以如果我的问题的答案似乎很明显,请多多包涵。
import os
import discord
import subprocess
from discord.ext import commands
bot = commands.Bot(command_prefix=".")
allowed_IDs = [1234567890]
@bot.event
async def on_ready():
print("Bot is online")
@bot.command()
async def tex(ctx, *, code):
if ctx.author.id in allowed_IDs:
await subprocess.call(f"pdflatex -output-directory=tex -jobname={ctx.author.id} -interaction=nonstopmode -no-shell-escape tex/default.tex '\begin{{document}}{code}\end{{document}}'")
await ctx.send(file=discord.File(f"tex/{ctx.author.id}.pdf"))
else:
await ctx.send("You cannot use this command")
bot.run(os.getenv("TOKEN"))
根据@Łukasz Kwieciński 的建议,我从 subprocess.call
中删除了 await
,事实证明这就是我的代码未按预期工作的原因。非常感谢您的帮助。