【发布时间】:2021-04-30 14:26:41
【问题描述】:
我正在尝试向我的 discord.py 机器人添加介绍功能。这就是我希望它的工作方式:
有人发送“.intro”,机器人开始向用户提出一堆个人问题。一旦他们回答了所有问题,机器人就会制作一个嵌入文件,将所有这些答案存储在其中,并将嵌入文件发送到一个名为“intro”的频道。然后,当有人想要查找特定用户的介绍时,他们会执行“.whois @user”,这会告诉机器人找到由提到的用户创建的介绍,因此机器人可以将其发回。当有人已经做了他们的介绍并想要编辑它时,他们再次执行“.intro”,并输入所需的答案,机器人会在“intro”频道中编辑他们的介绍。
我对编码很陌生,我不知道如何实现它。我已经编写了用于制作所需介绍嵌入的代码,但我不知道如何将不同人的答案存储在不同的嵌入中。任何帮助将不胜感激!谢谢。
这是我的介绍齿轮:
import discord
from discord.ext import commands
import asyncio
class IntroSystem(commands.Cog):
def __init__(self, client):
self.client = client
@commands.command()
async def intro(self, ctx):
global name, location, age, gender, hobbies
await ctx.send("What's your name?")
try:
name = await self.client.wait_for(
"message",
timeout=20,
check=lambda message: message.author == ctx.author
and message.channel == ctx.channel
)
except asyncio.TimeoutError:
await ctx.send('Timeout! Restart by saying `.intro`')
return
await ctx.send("Where do you live?")
try:
location = await self.client.wait_for(
"message",
timeout=20,
check=lambda message: message.author == ctx.author
and message.channel == ctx.channel
)
except asyncio.TimeoutError:
await ctx.send('Timeout! Restart by saying `.intro`')
return
await ctx.send("How old are you?")
try:
age = await self.client.wait_for(
"message",
timeout=20,
check=lambda message: message.author == ctx.author
and message.channel == ctx.channel
)
except asyncio.TimeoutError:
await ctx.send('Timeout! Restart by saying `.intro`')
return
await ctx.send("What's your gender? `Male, Female or Non Binary`")
try:
gender = await self.client.wait_for(
"message",
timeout=20,
check=lambda message: message.author == ctx.author
and message.channel == ctx.channel
)
except asyncio.TimeoutError:
await ctx.send('Timeout! Restart by saying `.intro`')
return
await ctx.send("What are your hobbies or interests?")
try:
hobbies = await self.client.wait_for(
"message",
timeout=60,
check=lambda message: message.author == ctx.author
and message.channel == ctx.channel
)
except asyncio.TimeoutError:
await ctx.send('Timeout! Restart by saying `.intro`')
return
embed = discord.Embed(
title='',
description='',
colour=discord.Color.blue()
)
embed.set_thumbnail(url=ctx.message.author.avatar_url)
embed.set_author(name=ctx.message.author, url=ctx.message.author.avatar_url)
embed.add_field(name="Name", value=name.content, inline=True)
embed.add_field(name="Location", value=location.content, inline=True)
embed.add_field(name="Age", value=age.content, inline=True)
embed.add_field(name="Gender", value=gender.content, inline=False)
embed.add_field(name="Hobbies", value=hobbies.content, inline=False)
await ctx.send(embed=embed)
def setup(client):
client.add_cog(IntroSystem(client))
【问题讨论】:
标签: python discord bots discord.py discord.py-rewrite