import discord, asyncio, time, discord.guild, random, os, youtube_dl
import os
import asyncio
import math
import random
import youtube_dl
import json
from discord.ext import commands, tasks
from discord.ext.commands import Bot, guild_only
from itertools import cycle
def get_prefix(client, message):
with open('prefixes.json', 'r') as f:
prefixes = json.load(f)
return prefixes[str(message.guild.id)]@client.event
async def on_ready():
change_status.start()
print('Bot is online')
@tasks.loop(seconds=3600)
async def change_status():
await client.change_presence(status=discord.Status.idle, activity=discord.Game(next(status)))
@client.event
def on_guild_join(client, message):
with open('prefixes.json', 'r') as f:
prefixes = json.load(f)
prefixes[str(message.guild.id)] = '.'
with open('prefixes.json', 'w') as f:
json.dump(prefixes, f, indent=4)
@client.event
async def on_guild_remove(guild):
with open('prefixes.json', 'r') as f:
prefixes = json.load(f)
prefixes.pop(str(guild.id))
with open('prefixes.json', 'w') as f:
json.dump(prefixes, f, indent=4)
@client.command(pass_context = True)
async def prefix(ctx, prefix):
with open('prefixes.json', 'r') as f:
prefixes = json.load(f)
prefixes[str(ctx.guild.id)] = prefix
with open('prefixes.json', 'w') as f:
json.dump(prefixes, f, indent=4)错误是-回溯(最近一次调用):文件“c:\Users\PC\OneDrive\code\mbot.py\3mbot\main code\mbot.py",第71行,在def on_guild_join(客户端,消息):文件on_guild_join第1002行,事件引发TypeError(‘事件注册必须是一个coroutine函数’) TypeError:事件注册必须是一个coroutine函数。
我使用python3.9.0和最新的pip。以及最新的discord.py github。
发布于 2020-11-25 11:28:36
它是协同作用的
async def on_guild_join不
def on_guild_joinhttps://stackoverflow.com/questions/65002409
复制相似问题