I'm trying to add an intro feature to my discord.py bot. This is how I want it to work:
Someone sends ".intro", and the bot starts asking a bunch of personal questions to the user. Once they answer all the questions, the bot makes an embed storing all those answers in it, and sends the embed to a channel called "intro". And then, when someone wants to find the intro of a particular user, they do ".whois @user", which tells the bot to find the intro created by the mentioned user, so the bot can send it back. When someone has already made their introduction and wants to edit it, they do ".intro" once again, and enter the required answers, and the bot edits their intro in the "intro" channel.
I'm very new to coding, and I have no idea how to implement this. I have wrote the code for making the required intro embed, but I don't have a clue on how to store different people's answers in different embeds. Any help would be highly appreciated! Thank you.
This is my intro cog:
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))
question from:
https://stackoverflow.com/questions/65907528/how-to-make-a-working-introduction-feature-in-my-discord-py-bot