如何从没有参数discord.py的命令中获取服务器对象

时间:2018-05-30 19:48:01

标签: python python-3.x discord.py

我正在尝试创建一个机器人,当我执行!info时,它会在控制台中显示服务器信息而不使用Python上的discord.py传递任何参数。我发现的所有内容都涉及传递论据。

这是我到目前为止所尝试的:

@bot.command()
@asyncio.coroutine
def info(ctx):
    server = ctx.message.author.server
    server_name = server.name
    server_id = server.id
    server_owner = server.owner.name

    print("server name: {}"
          "server id: {}"
          "server owner: {}"
          .format(server_name, server_id, server_owner))

当跑步时,它会在控制台中显示:

Ignoring exception in command move
Traceback (most recent call last):
  File "D:\PycharmProjects\Movey\venv\lib\site-packages\discord\ext\commands\bot.py", line 846, in process_commands
    yield from command.invoke(ctx)
  File "D:\PycharmProjects\Movey\venv\lib\site-packages\discord\ext\commands\core.py", line 367, in invoke
    yield from self.prepare(ctx)
  File "D:\PycharmProjects\Movey\venv\lib\site-packages\discord\ext\commands\core.py", line 345, in prepare
    yield from self._parse_arguments(ctx)
  File "D:\PycharmProjects\Movey\venv\lib\site-packages\discord\ext\commands\core.py", line 304, in _parse_arguments
    transformed = yield from self.transform(ctx, param)
  File "D:\PycharmProjects\Movey\venv\lib\site-packages\discord\ext\commands\core.py", line 212, in transform
    raise MissingRequiredArgument('{0.name} is a required argument that is missing.'.format(param))
discord.ext.commands.errors.MissingRequiredArgument: ctx is a required argument that is missing.

1 个答案:

答案 0 :(得分:0)

您需要将#comments %h2.comment_count= pluralize(@post.comments.count, "Comment") - @comments.each do |comment| .comment %span %p.username= comment.user.name %p.username says: %p.content= comment.content 传递给pass_context=True

@bot.command