change_presence()采用1个位置参数,但给出了2个

时间:2018-02-27 21:29:30

标签: python discord.py

我在python中遇到问题,我正在编写自己的discord.py机器人,我真的很讨厌问题。

我的代码:

    import discord
from discord.ext import commands
from discord.ext.commands import Bot
import asyncio
import random


client = discord.Client()


bot = commands.Bot(command_prefix='!')

print ("Discord version: " + discord.__version__)

@bot.event
async def on_ready():
print ("Logged in as " + bot.user.name)
await client.change_presence(discord.Game(name="use !commands"))

1 个答案:

答案 0 :(得分:2)

尝试将change_presence中的位置参数更改为关键字参数:根据the docs,这将是game

因此

client.change_presence(discord.Game(name="use !commands"))

client.change_presence(game=discord.Game(name="use !commands")).

此外,如果我们查看discord.py的源代码,我们就会看到错误的确切原因。

Line 409 in this filechange_presence定义为

def change_presence(self, *, game=None, status=None, afk=False, since=0.0, idle=None)

我们可以在*参数之后看到星号(self),它是Python 3语义,用于仅接受星号后的关键字参数。

您可以查看this StackOverflow answer了解更多信息。

这意味着self之后的所有参数都是纯粹的关键字参数(需要一个标识符),你传递的参数加上self(自动传入)在最大位置时产生两个位置参数参数只是一个(self)。因此,您必须将位置参数更改为关键字1。

相关问题