对我来说可能很难,但是我相信stackoverflow的力量,
我需要在机器人上输入一个数字作为机器人状态。
此处:http://gamers-control-2.000webhostapp.com/count.txt
它的照片:Picture
#time显示状态=在空白网站中创建的文本=“ 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的新手
答案 0 :(得分:1)
您需要先从开头导入请求
import requests
然后在准备好的事件之前
count = requests.get('http://gamers-control-2.000webhostapp.com/count.txt')
然后将其设置为
await client.change_presence(game=discord.Game(name=count.text, type=3))
答案 1 :(得分:0)
我这样使用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"))
答案 2 :(得分:0)
这是我用的
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'))```