我编写了一个Discord自我机器人,该机器人发送的图片的行为就像没有硝基的全球表情。
示例:
我:!好
me(bot):ok.png
但是,当我编辑代码并添加更多图片和其他东西并再次加载时(通过在cmd中执行“ mybot.py”),大约需要5分钟才能最终打印“ Self bot working”。在cmd窗口中...是什么问题?我不认为我的代码有问题,因为它总体上可以正常工作。我正在使用python 3.6和Windows。
import discord
import asyncio
client = discord.Client()
@client.event
async def on_ready():
print("nonitro Loaded.\n")
@client.event
async def on_message(message):
if message.author == client.user:
if(message.content.startswith("!ok")):
emo = "./img/ok.png"
async for msg in client.logs_from(message.channel,limit=1):
await client.delete_message(msg)
await client.send_file(message.channel, emo)
if message.author == client.user:
if(message.content.startswith("!xd")):
emo = "./img/xd.png"
async for msg in client.logs_from(message.channel,limit=1):
await client.delete_message(msg)
await client.send_file(message.channel, emo)
if message.author == client.user:
if(message.content.startswith("!coffee")):
emo = "./img/coffee.png"
async for msg in client.logs_from(message.channel,limit=1):
await client.delete_message(msg)
await client.send_file(message.channel, emo)
if message.author == client.user:
if(message.content.startswith("!thonk")):
emo = "./img/thonk.png"
async for msg in client.logs_from(message.channel,limit=1):
await client.delete_message(msg)
await client.send_file(message.channel, emo)
if message.author == client.user:
if(message.content.startswith("!like")):
emo = "./img/like.png"
async for msg in client.logs_from(message.channel,limit=1):
await client.delete_message(msg)
await client.send_file(message.channel, emo)
if message.author == client.user:
if(message.content.startswith("!kek")):
emo = "./img/kek.png"
async for msg in client.logs_from(message.channel,limit=1):
await client.delete_message(msg)
await client.send_file(message.channel, emo)
if message.author == client.user:
if(message.content.startswith("!bobross")):
emo = "./img/bobross.png"
async for msg in client.logs_from(message.channel,limit=1):
await client.delete_message(msg)
await client.send_file(message.channel, emo)
if message.author == client.user:
if(message.content.startswith("!likethis")):
emo = "./img/likethis.png"
async for msg in client.logs_from(message.channel,limit=1):
await client.delete_message(msg)
await client.send_file(message.channel, emo)
client.run("my token", bot=False)
答案 0 :(得分:0)
您无需从聊天记录中删除日志即可删除一条消息,只需执行
@client.event
async def on_message(message):
if message.author.id == "your id" and "!ok" == message.content:
await client.delete_message(message)
await client.send_file(message.channel,"path/to/file")
return
client.run("token",bot=False)
仅当消息的内容为!ok且您的ID为!ok时,才会发送消息