所以我正在尝试制作一个从本地目录发布随机图像的机器人。我似乎不知道该怎么办。我花了一些时间在网上看一些方法,但是大多数方法与嵌入式链接有关。
#Version 1.1.0
import os
import random
import discord
import asyncio
from discord.ext import commands
from discord.ext.commands import Bot
#Release#
TOKEN = 'token#'
#WIP#
#TOKEN = 'TOKEN#'
default_emojis = [
"?"
]
bot = commands.Bot(command_prefix='!croc')
@bot.event
async def on_ready():
print("CrocBOT | Version 1.1.0")
@bot.event
async def on_message(message):
print('A user has entered a command.')
await bot.process_commands(message)
@bot.event
async def on_message(message):
if message.content.startswith('version'):
channel = message.channel
await channel.send('CrocBOT | Version 1.1.0')
@bot.event
async def on_message(message):
if message.author == bot.user:
return
if "croc" in message.content.lower():
await message.add_reaction("?")
elif "aligator" in message.content.lower():
await message.add_reaction("?")
elif "caiman" in message.content.lower():
await message.add_reaction("?")
elif "gharial" in message.content.lower():
await message.add_reaction("?")
elif "alligator" in message.content.lower():
await message.add_reaction("?")
elif "liopleurodon" in message.content.lower():
await message.add_reaction("?")
elif "nile" in message.content.lower():
await message.add_reaction("?")
elif "sagan" in message.content.lower():
await message.add_reaction("?")
elif "krokodil" in message.content.lower():
await message.add_reaction("?")
elif "sobek" in message.content.lower():
await message.add_reaction("?")
elif "spin" in message.content.lower():
await message.add_reaction("?")
elif "roll" in message.content.lower():
await message.add_reaction("?")
elif "крокодил" in message.content.lower():
await message.add_reaction("?")
elif "gavialis" in message.content.lower():
await message.add_reaction("?")
elif "?" in message.content.lower():
await message.add_reaction("?")
elif ":crocodile:" in message.content.lower():
await message.add_reaction("?")
#with open('my_image.png', 'rb') as f:
# picture = discord.File(f)
# await channel.send(channel, picture)
#@bot.command()
#async def pic():
# fp = random.choice(os.listdir("D:\Discord_BOTs\BOT\CrocBOT\crocs"))
# await bot.send_file(ctx.message.channel, "D:\Discord_BOTs\BOT\CrocBOT\crocs{}".png(fp))
bot.run(TOKEN)
我在这里尝试了一些操作,但是将它们更改为便笺,因为它们似乎根本无法工作。另外,我希望发布本地目录中的图像。 任何帮助将不胜感激。
谢谢!