嗨,当我尝试加载齿轮时,我收到语法错误
await self.bot.send_message(channel, content=":warning: @mods There is a possible raid in progress! :warning:")
^
SyntaxError: invalid syntax
这就是我的工作
import asyncio
import os
import discord
from datetime import datetime
from __main__ import send_cmd_help, settings
from discord.ext import commands
from .utils import checks
from .utils.dataIO import dataIO
class AntiRaid():
"""Alerts Staff about possible incoming raids"""
def __init__(self, bot):
self.bot = bot
self.settings = dataIO.load_json("data/anti_raid/settings.json")
async def on_member_join(self, member):
server = member.server
if self.settings[server.id]["time_since_last_reset"] is None:
reset_time = 999 # a big number to trigger the timeout now
else:
last_reset = datetime.strptime(self.settings[server.id]["time_since_last_reset"], "%Y-%m-%d %H:%M:%S.%f")
reset_time = (datetime.now() - last_reset).total_seconds()
if reset_time > 30:
self.settings[server.id]["join_count"] = 0
self.settings[server.id]["time_since_last_reset"] = str(datetime.now())
dataIO.save_json("data/lockdown/settings.json", self.settings)
if self.settings[server.id]["join_count"] < self.settings[server.id]["max_joins"]:
self.settings[server.id]["join_count"] += 1
dataIO.save_json("data/lockdown/settings.json", self.settings)
return
if (self.settings[server.id]["join_count"] >= self.settings[server.id]["max_joins"]) and reset_time <= 30:
channel_id = self.settings[server.id]["channel"]
channel = self.bot.get_channel(channel_id)
await self.bot.send_message(channel, content=":warning: @everyone There is a possible raid happening! :warning:")
self.settings[server.id]["join_count"] = 0
self.settings[server.id]["time_since_last_reset"] = str(datetime.now())
dataIO.save_json("data/lockdown/settings.json", self.settings)
return
我不确定我在做什么错,这里有人可以帮助我吗?谢谢
答案 0 :(得分:0)
该错误是因为您的await
不在协程的主体中(async def
函数)。修正缩进,使所有适当的代码都在on_member_join
内部。照原样,on_member_join
只有一行。