踢前Discord bot python DM消息

时间:2020-05-03 19:10:09

标签: python bots discord

我对不和谐的机器人还很陌生,所以我想知道这里是否有人可以帮助我,我编写了一个踢人代码,我想添加一个DM是被踢人但在发出!kick命令之后的人。

@bot.command()
async def kick(ctx, member: discord.Member=None):
    if not member:
        await ctx.send('Please mention a member')
        return
    await member.kick()
    await ctx.send(f'{member.display_name}\'s was kicked from the server')

1 个答案:

答案 0 :(得分:0)

您只需要创建dm频道并发送消息即可。

尝试添加以下两行:

@bot.command()
async def kick(ctx, member: discord.Member = None):
    if member is None:
        await ctx.send(f'{ctx.author.mention} Please mention a member')
        return
    channel = await member.create_dm() # line 1 create channel
    await channel.send('You are getting kicked') # line 2 send the message
    await member.kick()
    await ctx.send(f'{member.display_name}\'s was kicked from the server')