我如何使机器人通过discord.py将消息发送到特定频道?

时间:2020-02-13 08:17:55

标签: python discord.py

最近,我试图发出一个kick命令,它的作用是将成员踢出去,并将有关该踢的消息发送到mod_log通道。这是我的代码:

@commands.command()
async def kick(self, ctx, member: discord.Member, *reasontext):
    """
    .kick <member: discord.Member> <reasontext(optional)>

    Kicks a member.
    """
    guild_to_load_config: discord.Guild = member.guild

    reasonoutput = ""

    for word in reasontext:
        reasonoutput += word
        reasonoutput += " "
        reasonoutput.strip()

    # Kicks the member.
    await member.kick(reason=reasonoutput)

    # Sends a confirmation message.
    await ctx.send(f"Successfully kicked {member} for {reasonoutput}.")

    def get_channel_id():
        with open(f'{guild_to_load_config.id}_config.yaml') as channel_to_get:
            mod_log_channel = yaml.safe_load(channel_to_get)

            channel_id: discord.TextChannel = mod_log_channel['plugins']['logging']['type']['moderation_log']['channel']

            return channel_id

    channelID: discord.TextChannel = get_channel_id()

    kickEmbed = discord.Embed(title=":foot: A Member has been Kicked from the server", colour=0xa6f7ff)

    kickEmbed.add_field(name="Member", value=f"{member.mention}", inline=False)

    kickEmbed.add_field(name="Reason", value=f"{reasonoutput}")

    await channelID.send(embed=kickEmbed)

但是,僵尸程序只踢踢成员并发送确认消息,而没有向踢踢的mod_logs发送消息。我怎样才能解决这个问题?请问我也有做错事情,以便再次防止此类错误:D

0 个答案:

没有答案