我正在嘗試讓機器人踢出扮演該角色一周的玩家,但我遇到了一些錯誤。
2022-06-23T04:48:44.209432 00:00 app[worker.1]: Ignoring exception in on_member_update
2022-06-23T04:48:44.209541 00:00 app[worker.1]: Traceback (most recent call last):
2022-06-23T04:48:44.209560 00:00 app[worker.1]: File "/app/.heroku/python/lib/python3.10/site-packages/discord/client.py", line 343, in _run_event
2022-06-23T04:48:44.209561 00:00 app[worker.1]: await coro(*args, **kwargs)
2022-06-23T04:48:44.209570 00:00 app[worker.1]: File "/app/ttsbot.py", line 112, in on_member_update
2022-06-23T04:48:44.209571 00:00 app[worker.1]: max_join_time_1 = timenow() - timedelta(weeks=1)
2022-06-23T04:48:44.209592 00:00 app[worker.1]: TypeError: 'datetime.datetime' object is not callable
import discord
import asyncio
import datetime
import math
import pytz
from discord.ext import commands
from discord.ext.commands import has_permissions, MissingPermissions
from discord.utils import get
from datetime import datetime, timedelta, timezone
TOKEN = "*something*"
intents = discord.Intents.all()
intents.members = True
bot = commands.Bot(command_prefix='.', intents = intents)
bot.remove_command('help')
utc=pytz.UTC
@bot.event
async def on_member_update(before, after):
if len(before.roles) < len(after.roles):
new_role = next(role for role in after.roles if role not in before.roles)
guild = bot.get_guild(*something*)
if '.? ??? ??' in new_role.name:
role_name1 = ".? ??? ??"
role1 = discord.utils.get(guild.roles, name=role_name1)
await asyncio.sleep(604800)
timenow = datetime.now(timezone.utc)
max_join_time_1 = timenow() - timedelta(weeks=1)
current_timezone_time = after.joined_at
new_timezone_time = current_timezone_time.astimezone(pytz.UTC)
log_channel = bot.get_channel(*something*)
if after in role1.members and new_timezone_time < max_join_time_1:
await after.kick(reason="????? ???? ??????.")
embed = discord.Embed(title="??",
colour=0xB11B1B,
timestamp=datetime.now())
embed.set_thumbnail(url=after.avatar_url)
fields = [("??", f"{after.name}", False),
("??", f"7?? ????? ??? ????.", False)]
for name, value, inline in fields:
embed.add_field(name=name, value=value, inline=inline)
await log_channel.send(embed=embed)
else:
pass
else:
pass
我在stackoverflow中嘗試了一些相關的答案,比如TypeError: 'module' object is not callable和TypeError: 'datetime.datetime' object is not callable,但沒??有任何效果。也許是因為這是我第一次使用 python?
抱歉我的英語不好,但我需要一些幫助。
-編輯-
我的第一個代碼實際上是
@bot.event
async def on_member_update(before, after):
if len(before.roles) < len(after.roles):
new_role = next(role for role in after.roles if role not in before.roles)
guild = bot.get_guild(*something*)
if '.? ??? ??' in new_role.name:
role_name1 = ".? ??? ??"
role1 = discord.utils.get(guild.roles, name=role_name1)
await asyncio.sleep(604800)
timenow = datetime.now
max_join_time_1 = timenow() - timedelta(weeks=1)
log_channel = bot.get_channel(*something*)
if after in role1.members and after.joined_at < max_join_time_1:
await after.kick(reason="????? ???? ??????.")
embed = discord.Embed(title="??",
colour=0xB11B1B,
timestamp=datetime.now())
embed.set_thumbnail(url=after.avatar_url)
fields = [("??", f"{after.name}", False),
("??", f"7?? ????? ??? ????.", False)]
for name, value, inline in fields:
embed.add_field(name=name, value=value, inline=inline)
await log_channel.send(embed=embed)
else:
pass
else:
pass
但后來我有了
TypeError: can’t compare offset-naive and offset-aware datetimes
錯誤,所以我將兩個時區都固定為UTC。
首先,當我在我的計算機上運行它時它運行良好,只有當我將它上傳到 heroku 時它才會出現錯誤。
但是在編輯之后,我也無法通過我的計算機運行它。
uj5u.com熱心網友回復:
這是問題所在:
timenow = datetime.now(timezone.utc)
max_join_time_1 = timenow() - timedelta(weeks=1)
# ^^
您創建一個datetime名為的物件timenow,然后嘗試在下一行呼叫它。
去掉括號:
timenow = datetime.now(timezone.utc)
max_join_time_1 = timenow - timedelta(weeks=1)
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/496324.html
標籤:Python 约会时间 heroku 不和谐 不和谐.py
下一篇:在R中計算會話持續時間
