gpt4 book ai didi

python - 属性错误: 'list' object has no attribute 'channel' discord. py

转载 作者:太空宇宙 更新时间:2023-11-03 21:05:12 25 4
gpt4 key购买 nike

我正在尝试创建一个功能,可以使用 https://www.youtube.com/watch?v=ZBVaH6nToyM 清除不和谐的聊天。 ,但是我认为我已经声明了 channel (channel = ctx.message.channel),但是输入 .clear 会导致错误

Ignoring exception in command clear
Traceback (most recent call last):
File "C:\Users\mark\AppData\Local\Programs\Python\Python36-
32\lib\site-packages\discord\ext\commands\core.py", line 50, in
wrapped
ret = yield from coro(*args, **kwargs)
File "C:/Users/mark/Desktop/purge.py", line 17, in clear
await client.delete_message(messages)
File "C:\Users\mark\AppData\Local\Programs\Python\Python36-
32\lib\site-packages\discord\client.py", line 1261, in delete_message
channel = message.channel
AttributeError: 'list' object has no attribute 'channel
import discord
from discord.ext import commands
from discord.ext.commands import Bot
TOKEN = "token here"
client = commands.Bot(command_prefix = '.')

@client.event
async def on_ready():
print("Bot is online")

@client.command(pass_context = True)
async def clear(ctx, amount=100):
channel = ctx.message.channel
messages = []
async for message in client.logs_from(channel,limit=int(amount)):
messages.append(messages)
await client.delete_message(messages)
await client.say('message has been deleted')

client.run(TOKEN)

最佳答案

您基本上是一遍又一遍地附加列表本身

my_list=[]
my_list.append(my_list)
print(my_list)

结果是这样的

>>[[[...]]

命令应该是这样的

@bot.command(pass_context=True)
async def clear(msg,amt:int=20): #can be converted into int via :type
messages=[]
async for i in bot.logs_from(msg.message.channel,limit=amt):
messages.append(i)
await bot.delete_messages(messages)

另外请注意,您无法批量删除超过 14 天的邮件,我认为这意味着您无法使用 delete_messages 且只能单独删除它

关于python - 属性错误: 'list' object has no attribute 'channel' discord. py,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55453909/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com