我正在使用我正在制作的机器人在 discord.py 中嵌入一个 httpexception 错误,我是这个机器人的新手,所以我不明白问题是什么。请帮忙
import discord
import os
import time
import discord.ext
from keep_alive import keep_alive
from discord.ext import commands
client = commands.Bot(command_prefix = '!')
@client.command()
async def ping(ctx):
ping_ms = round(client.latency * 1000)
if ping_ms <= 50:
embed = discord.Embed(description=f":green_circle: `{ping_ms} ms`", color=0x00FF00)
elif ping_ms <= 100:
embed = discord.Embed(description=f":yellow_circle: `{ping_ms} ms`", color=0xFFFF00)
elif ping_ms <= 200:
embed = discord.Embed(description=f":orange_circle: `{ping_ms} ms`", color=0xFFA500)
else:
embed = discord.Embed(description=f":red_circle: `{ping_ms} ms`", color=0xFF0000)
await ctx.send(embed=embed)
@client.command()
async def kick(ctx, member : discord.Member):
try:
await member.kick(reason=None)
await ctx.send("kicked "+member.mention)
except:
await ctx.send("bot does not have the kick members permission!")
@client.command()
@commands.has_role('Admin')
async def test(ctx):
await ctx.send(embed=discord.Embed(description='Test done', color=0x00ff00))
@client.command()
async def clear (ctx, number):
num = int(number)
await ctx.message.channel.purge(limit=num)
@client.event
async def on_ready():
await client.change_presence(status=discord.Status.idle, activity=discord.Activity(type=discord.ActivityType.playing, name='!help'))
print(f"{client.user} is online")
msg_num = 0
@client.event
async def on_message(message):
global msg_num
msg_num += 1
print(msg_num)
if msg_num >= 100:
await message.channel.send(embed=discord.Embed(discription = '`Chats count has reached a 100, clearing chat...`',color=0xff0000))
time.sleep(5)
await message.channel.purge(limit=101)
msg_num = 0
keep_alive()
client.run(os.getenv("TOKEN"))
这是图片: this is the image of the error
注意:
答案 0 :(得分:0)
你写的是 discription
而不是 description
:
# here
await message.channel.send(embed=discord.Embed(discription = '`Chats count has reached a 100, clearing chat...`', color=0xff0000))
那么对于第二个问题,您的命令将不会被处理,因为您覆盖了 on_message
并且没有包含 client.process_commands(message)
:
@client.event
async def on_message(message):
await client.process_commands(message)
global msg_num
msg_num += 1
if msg_num >= 100:
await message.channel.send(embed=discord.Embed(description = '`Chats count has reached a 100, clearing chat...`',color=0xff0000))
time.sleep(5)
await message.channel.purge(limit=101)
msg_num = 0
此外,您不应使用 time.sleep
,因为它会在执行时阻塞您的整个代码。您应该使用 asyncio.sleep
:
import asyncio
...
await asyncio.sleep(5)