【问题标题】:change discord.py bot status更改 discord.py 机器人状态
【发布时间】:2019-05-26 12:20:24
【问题描述】:

这对我来说可能很难,但我相信 stackoverflow 的力量,

我需要在我的机器人上输入一个数字作为机器人状态。

这里:http://gamers-control-2.000webhostapp.com/count.txt

还有图片:Picture

#time to show status = 在空白网站中创建的文本 = "41"

#http://gamers-control-2.000webhostapp.com/count.txt

#一些方法,你说我可以输入数字,我说网络中的数字 每次都更改,因此我需要获取该数字以将其显示为机器人状态。

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


Client = discord.client
client = commands.Bot(command_prefix = '!')
Clientdiscord = discord.Client()




@client.event
async def on_ready():

 await client.change_presence(game=discord.Game(name=http://gamers-control-2.000webhostapp.com/count.txt, type=3))

 print('test ready')

client.run("....")

我是 discord.py 的新手

【问题讨论】:

  • 您遇到的问题不清楚。需要注意的是,您需要在 discord.Game() 调用中的 name= 属性中将 url 用引号括起来。
  • 为此我不知道如何获得该文本值(机器人状态)= count.txt(内部文本)

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


【解决方案1】:

这是我用的

async def on_ready():
    print(f'We have logged in as {bot.user}')
    print('Ready!')
    return await bot.change_presence(activity=discord.Activity(type=3, name='Add status here'))```

【讨论】:

  • 1 = 播放,2 = 聆听,3 = 观看
【解决方案2】:

我这样使用await bot.change_presence()

注意:

我遗漏了部分代码

@bot.event
async def on_ready():
    replit.clear()
    print(f'Logged in as {bot.user.name} - {bot.user.id}')
    bot.remove_command('help')
    await bot.change_presence(status=discord.Status.online, activity=discord.Game("mod help"))

【讨论】:

    【解决方案3】:

    一开始需要先导入请求

    import requests
    

    然后在ready事件之前

    count = requests.get('http://gamers-control-2.000webhostapp.com/count.txt')
    

    然后你把它设置为

    await client.change_presence(game=discord.Game(name=count.text, type=3))
    

    【讨论】:

    • 忽略 on_ready Traceback 中的异常(最后一次调用):文件“C:\Users\Hema\AppData\Local\Programs\Python\Python36-32\lib\site-packages\discord\client .py”,第 307 行,从 getattr(self, event)(*args, **kwargs) 产生的 _run_event 文件“C:\Users\Hema\Desktop\GC_Bot.py”,第 25 行,on_ready await client.change_presence (activity=Game(name=count.text)) TypeError: change_presence() got an unexpected keyword argument 'activity'
    • 我的回复没有考虑到你没有使用重写分支。我已将响应编辑为更正确。请立即尝试
    • 工作,你是最棒的
    猜你喜欢
    • 1970-01-01
    • 2019-06-15
    • 2020-11-06
    • 2020-03-26
    • 2021-01-11
    • 2021-03-10
    • 1970-01-01
    • 1970-01-01
    • 2020-12-05
    相关资源
    最近更新 更多