TypeError:注册的事件必须是协同程序函数discord.py

2024-04-24 18:14:41 发布

您现在位置:Python中文网/ 问答频道 /正文

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\Documents\3mbot\main code\mbot.py”,第71行,在 def on_guild_join(客户端,消息): 事件中的文件“C:\Users\PC\AppData\Local\Programs\Python\39\lib\site packages\discord\client.py”,第1002行 raise TypeError('注册的事件必须是协同程序函数') TypeError:注册的事件必须是协同程序函数

我正在使用Python3.9.0和最新的pip。和最新的discord.py github


Tags: importclientidjsonmessageprefixdefas