繁体   English   中英

有没有办法在 discord.command() 中找到多行参数?

[英]Is there a way to find multiline arguments in discord.command()?

我一直在尝试构建一个 Discord 机器人,作为社交媒体网站以及其他一些功能。 但我坚持发布命令。 没有办法(或者至少在我看来)我无法从 discord bot 用户那里获得多行参数。 这是到目前为止的功能:

@bot.command() 
async def post(ctx, theme, name, *description):
  sep = " "
  description1 = sep.join(description)
  if theme not in ['news', 'challenge', 'share', 'announcement', 'question', 'tutorial']:
    await ctx.send(f"Invalid theme: {theme}")
  else:
    with open("global.json", "r") as globe:
      dat = json.load(globe)
    with open(f"profiles/{ctx.author}.json", "r") as author:
      auth = json.load(author)
    with open(f"posts.json", "r") as post:
      posts = json.load(post)
    post_dict = {"name": name, "theme": theme, "desc": description1, "id": dat["postId"], "likes": [], "comments": []}
    posts.append(post_dict)
    auth["Posts"].append([name, dat["postId"]])
    dat['postId'] += 1
    with open("global.json", "w") as globe1:
      dat = json.dump(dat, globe1)
    with open(f"profiles/{ctx.author}.json", "w") as author1:
      auth = json.dump(auth, author1)
    with open(f"posts.json", "w") as post1:
      posts = json.dump(posts, post1)
    embedVar = discord.Embed(description=f"A {str(theme).title()} Post under the name of {name} has been created, {ctx.author}!", color=0x00ff00)
    await ctx.send(embed=embedVar)

描述接受多字参数,但不接受多行参数。 有没有办法可以接受多行? 或者有什么其他方法可以解决我的问题?

像这样制作命令,并完全删除description1 无论是什么,它都会将名称后面的任何内容作为描述。 文档

@bot.command() 
async def post(ctx, theme, name, *,description):

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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