如何制作一个记录事件的discord.py bot ?



例如,如果我要记录一个事件,我会说>log,然后机器人会发邮件给我问问题,首先是"你的用户名是什么?"你有搭档主持吗?"如果没有,请输入N/A"有多少与会者?"(#) " "谁通过的用户名?"谁失败了?""形象?,然后它会在一个频道中记录:主持人:(用户名)合作主持人:(用户名或无)与会者:#通过(用户名):失败(用户名):证明:(图片)

无论如何,我怎么做呢?有人能寄过来吗?(我使用@bot.command()形式)

我什么都没试过,我不知道怎么开始

下面是如何使用Python中的discord.py库实现此功能的示例:

import discord
from discord.ext import commands
bot = commands.Bot(command_prefix='>')
@bot.event
async def on_ready():
print(f'Logged in as {bot.user.name}')
@bot.command()
async def log(ctx):
def check(m):
return m.author == ctx.author and m.channel == ctx.channel
await ctx.send("What's your username?")
username = await bot.wait_for('message', check=check)
username = username.content
await ctx.send("Did you have a Co-Host? Put N/A if none")
co_host = await bot.wait_for('message', check=check)
co_host = co_host.content
await ctx.send("How many attendees? (#)")
attendees = await bot.wait_for('message', check=check)
attendees = attendees.content
await ctx.send("Usernames of who passed? (Separate with spaces)")
passed = await bot.wait_for('message', check=check)
passed = passed.content.split()
await ctx.send("# of who failed?")
failed_count = await bot.wait_for('message', check=check)
failed_count = failed_count.content
failed = []
for i in range(int(failed_count)):
await ctx.send(f"Username of failed attendee {i+1}?")
failed_user = await bot.wait_for('message', check=check)
failed.append(failed_user.content)
await ctx.send("Please provide an image (attachment) as proof.")
image = await bot.wait_for('message', check=check)
proof = image.attachments[0].url
log_message = f"Host: {username}nCo-Host: {co_host}nAttendees: {attendees}nPassed: {', '.join(passed)}nFailed: {', '.join(failed)}nProof: {proof}"
# You can change the channel ID to the desired channel where you want the log to be posted
log_channel = bot.get_channel(123456789)  
await log_channel.send(log_message)
await ctx.send("Log created successfully!")
bot.run('YOUR_BOT_TOKEN_HERE')

注意:您需要将'YOUR_BOT_TOKEN_HERE'替换为您实际的bot令牌,并将log_channel变量更新为您希望发布日志的适当通道ID。此外,如果您还没有安装不和谐.py库,您可能需要安装,使用pip install不和谐.py。

可以使用以下代码作为起点。对于某些上下文,我使用斜杠命令和文档从头开始构建一个discord.py bot。

@bot.command()
async def log(ctx):
author = ctx.author
def check(msg):
return msg.author == author and msg.channel == ctx.channel

await author.send("What's your username?")
response = await bot.waitfor('message', check=check)
username = response.content

最新更新