我正在尝试使用discord.py 将我自己的个人资料状态(不是机器人)更改为在一天中的特定时间不可见。
代码应该做的是,它从我的计算机获取当前时间,并根据一天中的时间以及在这些情况下上线/离线返回 True 或 False。
即使代码没有引发任何异常,它也不会让我的个人资料变得不可见/在线。
另外,我使用的是 1.7.0 版本,因为他们在 2.0.0 版本之后删除了 selfbots
这是我到目前为止想到的:
from discord import *
from discord.ext import commands
from essentials import *
from datetime import time
import time as t
import datetime
import discord
import asyncio
intents = discord.Intents().all()
intents.typing = False
intents.presences = False
#Local variables
token = "my-token"
prefix = "."
bot = commands.Bot(command_prefix=prefix, intents=intents, help_command=None, self_bot=True)
# ---------------------------------------------------------
# Definitions
def getTime():
dt = datetime.datetime
timestamp = dt.now().time() # Throw away the date information
t = string.before(str(timestamp), ".")
t = dt.strptime(t, '%H:%M:%S')
hour = t.hour
return hour
def goInvis():
hour = getTime()
time_stamps = [12,22]
if time < time_stamps[0] or time > time_stamps[1]:
return True
else:
return False
# -------------------------------------------------------------------------
@bot.event
async def on_ready():
print("Ready")
while True:
if goInvis:
print("Went invis")
await bot.change_presence(status=discord.Status.offline)
else:
print("Went online")
await bot.change_presence(status=discord.Status.online)
t.sleep(2)
bot.run(token, bot=False)
您无法通过不和谐机器人更改自己的状态。也许它甚至违反了服务条款,但我不确定。