It is good to use commands.bot
instead of Client
because it is an extended version, as it inherits all the functionalities from Client
.
I see you have tried to migrate from the use of Client
to using commands.bot
, but have a few things in mind:
You do not want to use both at the same time, so this is wrong:
client = discord.Client(intents=intents)
bot = commands.Bot(command_prefix='!')
You should keep only the bot one.
Apart from that, you gotta replace the client
from the decorators and the calls inside the function. Your corrected code should look something like this:
import os
import discord
import csv
from collections import defaultdict
from discord.ext import commands
intents = discord.Intents.all()
outP = open("giveawayList.txt", "w")
bot = commands.Bot(command_prefix='!', intents=intents)
@bot.event
async def on_message(message):
if message == "!test":
await message.channel.send("you failed the test")
await bot.process_commands(message)
@bot.event
async def on_ready():
for guild in bot.guilds:
if guild.name == GUILD:
break
print(
f'{bot.user} is connected to the following guild:
'
f'{guild.name} (id: {guild.id})'
)
count = 0
for guild in bot.guilds:
for member in guild.members:
print(member)
if 'Bots' not in str(member.roles):
print(member.name, ' ')
outP.write(member.name)
outP.write("
")
count += 1
print('Number of members: ' + str(count))
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…