如何使用命令更改客户端状态?不和谐.py

时间:2021-07-26 10:34:33

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

status = None

@client.command()
async def setstatus(ctx, variable):
  global status
  print("Before", variable)
  status = variable
  await client.change_presence(activity=discord.Game(next(status)))
  await ctx.send(status)

以上是我目前拥有的代码,但无法正常工作。

错误: “等待 client.change_presence(activity=discord.Game(next(status))) 类型错误:'str' 对象不是迭代器"

目标是使用 !setstatus 更改机器人的存在文本。

请帮忙。

3 个答案:

答案 0 :(得分:0)

此错误告诉您 status 是一个字符串,而不是可以迭代的列表。

更改这一行: await client.change_presence(activity=discord.Game(next(status)))

到:

await client.change_presence(activity=discord.Game(status))

答案 1 :(得分:0)

玩游戏

await client.change_presence(activity=discord.Game(name="status"))

流式传输

await client.change_presence(activity=discord.Streaming(name="My Stream", url="stream url"))

听力

await client.change_presence(activity=discord.Activity(type=discord.ActivityType.listening, name="song"))

观看

await client.change_presence(activity=discord.Activity(type=discord.ActivityType.watching, name="a video"))

答案 2 :(得分:0)

看看how to change discord.py bot activity

# Setting `Playing ` status
await bot.change_presence(activity=discord.Game(name="a game"))

# Setting `Streaming ` status
await bot.change_presence(activity=discord.Streaming(name="My Stream", url=my_twitch_url))

# Setting `Listening ` status
await bot.change_presence(activity=discord.Activity(type=discord.ActivityType.listening, name="a song"))

# Setting `Watching ` status
await bot.change_presence(activity=discord.Activity(type=discord.ActivityType.watching, name="a movie"))