首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >TypeError:注册的事件必须是coroutine函数discord.py

TypeError:注册的事件必须是coroutine函数discord.py
EN

Stack Overflow用户
提问于 2020-11-25 10:03:52
回答 1查看 2.8K关注 0票数 1
代码语言:javascript
复制
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)]
代码语言:javascript
复制
@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。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-11-25 11:28:36

它是协同作用的

代码语言:javascript
复制
async def on_guild_join

代码语言:javascript
复制
def on_guild_join
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/65002409

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档