【问题标题】:How can I change client presence with a command? Discord.py如何使用命令更改客户端状态?不和谐.py
【发布时间】:2021-10-02 07:19:16
【问题描述】:
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)

以上是我目前拥有的代码,但它不起作用。

错误: “等待客户端.change_presence(活动=不和谐。游戏(下一个(状态))) TypeError: 'str' 对象不是迭代器"

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

请帮忙。

【问题讨论】:

  • 欢迎来到 StackOverflow。请阅读:stackoverflow.com/help/how-to-ask。它解释了如何改进您的问题,使其更易于阅读和理解确切的问题。希望对您有所帮助!

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


【解决方案1】:

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

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

到:

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

【讨论】:

  • @NDDevelopment 如果我已经解决了,你能接受这个作为正确答案吗
【解决方案2】:

玩游戏

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"))

【讨论】:

    【解决方案3】:

    看看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"))
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-03-26
      • 2021-06-11
      • 2021-09-05
      • 1970-01-01
      • 1970-01-01
      • 2019-03-12
      • 2022-01-26
      • 2021-09-27
      相关资源
      最近更新 更多