我想知道我的 snipe 命令是否可以以某种方式狙击图像,当我在图像上使用 snipe 时,它只会发送嵌入而没有消息。 这是基本的狙击命令:
bot.sniped_messages = {}
@bot.event
async def on_message_delete(message):
bot.sniped_messages[message.guild.id] = (message.content, message.author, message.channel.name, message.created_at)
@bot.command()
async def snipe(ctx):
try:
contents, author, channel_name, time = bot.sniped_messages[ctx.guild.id]
except:
await ctx.channel.send("Nemohu najít zprávu na snipenutí.")
return
embed = discord.Embed(description=contents,
color=ctx.author.color,
timestamp=time)
embed.set_author(name=f"{author.name}#{author.discriminator}", icon_url=author.avatar_url)
embed.set_footer(text=f"Smazáno v #{channel_name}")
await ctx.send(embed=embed)
最好能把代码发给我:P 谢谢!
狙击命令是获取最后删除的消息的命令
答案 0 :(得分:0)
使用 Message 您需要调用 message.attachments 将返回类型为 Attachment 的列表。但是,获取 URL 将不起作用,因为它会返回错误 404。
您必须将 URL 保存在 on_message 上,并将其保存到带有消息 ID 的变量中。然后检查删除时该消息 id 是否存在,如果存在,则返回 URL 或设置图像 URL。 Discord 不会从其数据库中删除图像。
答案 1 :(得分:0)
应该这样做
@bot.command()
async def check(ctx):
async for message in ctx.channel.history(limit=100): # gets the last 100 messages
if message.attachments == []: # checks if there are any attachments
pass # if there are no attachments it will just move on to the next one
else: # simple else statement
if message.author.id == 805485087181242388: # checks if the bot sent the picture, if it did it will not send it (replace 805485087181242388 with your bots id)
return # does nothing if the bot sended it
else: # another simple else statement
await ctx.send(message.attachments[0].url) # gets the last attachment sent, and only sends the url
return # breaks the command so that the bot will not keep on looking for attachments