您如何制作一个机器人,在几秒钟后,在Discord.py中删除了受欢迎的嵌入并删除嵌入的嵌入

发布于 2025-02-13 13:43:24 字数 607 浏览 1 评论 0原文

这是我的代码,但似乎不起作用。我很抱歉,但我仍然是新手,但是,我非常感谢您的帮助和批评者。

import discord
from discord.ext import commands
client = commands.Bot(command_prefix=prefix,
                      intents=discord.Intents.all())

@client.event
async def on_message_join(member):
    channel = client.get_channel(channelid)
    count = member.guild.member_count
    embed=discord.Embed(title=f"Welcome to {member.guild.name}", description=f"Hello there {member.name}!", footer=count) 
    embed.set_thumbnail(url=member.avatar_url) 

    await channel.send(embed=embed)
    time.sleep(5)
    message.delete(embed)

Here's my code but it seems like it doesn't work. I'm so sorry but, I'm still a newbie but, I would very much appreciate your help and critics.

import discord
from discord.ext import commands
client = commands.Bot(command_prefix=prefix,
                      intents=discord.Intents.all())

@client.event
async def on_message_join(member):
    channel = client.get_channel(channelid)
    count = member.guild.member_count
    embed=discord.Embed(title=f"Welcome to {member.guild.name}", description=f"Hello there {member.name}!", footer=count) 
    embed.set_thumbnail(url=member.avatar_url) 

    await channel.send(embed=embed)
    time.sleep(5)
    message.delete(embed)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

玩心态 2025-02-20 13:43:24

正确的不符合事件是抓住一个人加入您的不和谐的是:

async def on_member_join(member: discord.Member):

而不是on_message_join

轻松删除您可以首先使其成为字符串的消息:

msg = await channel.send(embed=embed)

然后获取ID:然后获取它:

msg_id = msg.id

然后删除它:

msg_todel = await channel.fetch_message(int(msg_id))

将其删除:

await msg_todel.delete()

The correct discord event to catch that a person joins your discord is:

async def on_member_join(member: discord.Member):

rather than on_message_join

To easily delete the message you can first make it a string:

msg = await channel.send(embed=embed)

then get it's id by:

msg_id = msg.id

then fetch it:

msg_todel = await channel.fetch_message(int(msg_id))

then delete it:

await msg_todel.delete()
千年*琉璃梦 2025-02-20 13:43:24

只需使用delete_after =秒,这是您想要的

import discord
from discord.ext import commands
client = commands.Bot(command_prefix=prefix,
                      intents=discord.Intents.all())

@client.event
async def on_message_join(member):
    channel = client.get_channel(channelid)
    count = member.guild.member_count
    embed=discord.Embed(title=f"Welcome to {member.guild.name}", description=f"Hello there {member.name}!", footer=count) 
    embed.set_thumbnail(url=member.avatar_url) 

    await channel.send(embed=embed, delete_after=5)

Just use delete_after=seconds, this exactly what's your wanted

import discord
from discord.ext import commands
client = commands.Bot(command_prefix=prefix,
                      intents=discord.Intents.all())

@client.event
async def on_message_join(member):
    channel = client.get_channel(channelid)
    count = member.guild.member_count
    embed=discord.Embed(title=f"Welcome to {member.guild.name}", description=f"Hello there {member.name}!", footer=count) 
    embed.set_thumbnail(url=member.avatar_url) 

    await channel.send(embed=embed, delete_after=5)
可是我不能没有你 2025-02-20 13:43:24

根据,您可以在5秒后编辑消息对象,然后将新的嵌入参数设置为,这似乎是您在这里追求的。

以下是您可以更改代码执行此操作的方式。

import discord
import asyncio # You will need to import this as well
from discord.ext import commands
client = commands.Bot(command_prefix=prefix,
                      intents=discord.Intents.all())

@client.event
async def on_message_join(member):
    channel = client.get_channel(channelid)
    count = member.guild.member_count
    embed=discord.Embed(title=f"Welcome to {member.guild.name}", description=f"Hello there {member.name}!", footer=count) 
    embed.set_thumbnail(url=member.avatar_url) 

    message_object = await channel.send(embed=embed) # You can save the message sent by attaching it to a variable. You don't need to send more calls to refetch it.
    
    '''
    time.sleep(5) <--- You should not use time.sleep() as it will stop your entire bot from doing anything else during these 5 seconds.

    Use asyncio.sleep() as a better alternative. Does the same thing as time.sleep() but other functions of your bot will still function, this is called a  blocking function.
    '''

    asyncio.sleep(5)
    
    await message_object.edit(embed = None)

除非您要删除整个消息,否则您只需使用delete_after即可获得此消息。

import discord
from discord.ext import commands
client = commands.Bot(command_prefix=prefix,
                      intents=discord.Intents.all())

@client.event
async def on_message_join(member):
    channel = client.get_channel(channelid)
    count = member.guild.member_count
    embed=discord.Embed(title=f"Welcome to {member.guild.name}", description=f"Hello there {member.name}!", footer=count) 
    embed.set_thumbnail(url=member.avatar_url) 

    await channel.send(embed=embed, delete_after = 5) # Just add this parameter at the end.

According to the discord.py docs, you could edit the message object after 5 seconds and then just set the new embed parameter to None, this seems to be what you're after here.

Below is a way you can alter your code to do this.

import discord
import asyncio # You will need to import this as well
from discord.ext import commands
client = commands.Bot(command_prefix=prefix,
                      intents=discord.Intents.all())

@client.event
async def on_message_join(member):
    channel = client.get_channel(channelid)
    count = member.guild.member_count
    embed=discord.Embed(title=f"Welcome to {member.guild.name}", description=f"Hello there {member.name}!", footer=count) 
    embed.set_thumbnail(url=member.avatar_url) 

    message_object = await channel.send(embed=embed) # You can save the message sent by attaching it to a variable. You don't need to send more calls to refetch it.
    
    '''
    time.sleep(5) <--- You should not use time.sleep() as it will stop your entire bot from doing anything else during these 5 seconds.

    Use asyncio.sleep() as a better alternative. Does the same thing as time.sleep() but other functions of your bot will still function, this is called a  blocking function.
    '''

    asyncio.sleep(5)
    
    await message_object.edit(embed = None)

Unless you want the entire message deleted, then you can just use delete_after in order to obtain this.

import discord
from discord.ext import commands
client = commands.Bot(command_prefix=prefix,
                      intents=discord.Intents.all())

@client.event
async def on_message_join(member):
    channel = client.get_channel(channelid)
    count = member.guild.member_count
    embed=discord.Embed(title=f"Welcome to {member.guild.name}", description=f"Hello there {member.name}!", footer=count) 
    embed.set_thumbnail(url=member.avatar_url) 

    await channel.send(embed=embed, delete_after = 5) # Just add this parameter at the end.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文