0
votes
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)

error is - Traceback (most recent call last): File "c:\Users\PC\OneDrive\Documents\3mbot\main code\mbot.py", line 71, in def on_guild_join(client, message): File "C:\Users\PC\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\client.py", line 1002, in event raise TypeError('event registered must be a coroutine function') TypeError: event registered must be a coroutine function

I'm using python 3.9.0 with the latest pip. and latest discord.py github.

1

1 Answers

1
votes

It's coroutine

async def on_guild_join

not

def on_guild_join