在有人加入并获得同一频道中某人的“y”确认后尝试添加角色
不确定我是否可以在中间添加另一个异步...
对不起,如果这是一个非常明显的问题,但我在网上得到的大多数答案都已经过时了,而且文档没有回答我所有的问题
这是我的尝试
import discord
from discord.ext import commands
intents = discord.Intents.default()
intents.members = True
bot = discord.ext.commands.Bot(command_prefix="$", intents=intents)
@bot.event
async def on_member_join(member):
await channel.send("{} has just joined. \nDo you know them (y/n)?".format(member.name))
print("someone joined")
async def on_message(message):
if "y" in message.content:
role = get(message.guild.roles, name="Hey i know you")
await member.add_roles(role, atomic=True)
await message.channel.send("added Hey i know you to {}".format(member.name))
答案 0 :(得分:0)
一种方法是使用 wait_for
函数。
@client.event
async def on_member_join(member):
channel = client.get_channel(your channel id)
guild = client.get_guild(your guild id)
await channel.send(f"{member.mention} joined!")
await asyncio.sleep(3)
await channel.send("{} has just joined. \nDo you know them (y/n)?".format(member.name))
msg = await client.wait_for("message")
if msg.content == "y":
role = guild.get_role(your rold id)
await member.add_roles(role)
await channel.send("Added role!")
elif msg.content == "n":
await channel.send("i wont add the role!")
return