Discord bot发送2条消息,而不是1条消息

时间:2020-05-01 23:41:14

标签: python discord discord.py

我的机器人响应我的命令发送了两次相同的消息。

Image of bot responding twice

请帮助我,我不知道该怎么办

import discord 
from discord.ext import commands
from discord.ext.commands import Bot
import youtube_dl

Bot = commands.Bot(command_prefix= '$')
Bot.remove_command('help')

@Bot.command()
async def hello(ctx):
    author = ctx.message.author
    await ctx.send(f"Hello {author.mention}")

@Bot.command()
@commands.has_permissions(administrator= True)
async def mute(ctx, member: discord.Member):
    mute_role = discord.utils.get(ctx.message.guild.roles, name= "Muted")
    await member.add_roles(mute_role)
    await ctx.send("Пользователь успешно замьючен")

@Bot.command()
@commands.has_permissions(administrator= True)
async def unmute(ctx, member: discord.Member):
    mute_role = discord.utils.get(ctx.message.guild.roles, name= "Muted")
    await member.remove_roles(mute_role)
    await ctx.send("Пользователь успешно размьючен")

@Bot.command()
@commands.has_permissions(administrator= True)
async def kick(ctx, member : discord.Member, *, reason=None):
    await member.kick(reason=reason)
    await ctx.send

@Bot.command()
@commands.has_permissions(administrator= True)
async def ban(ctx, member : discord.Member, *, reason="Вы нарушили правила сервера или же админ просто решил вас забанить :)"):
    await member.ban(reason=reason)
    await ctx.send('Пользователь получил БАН')

@Bot.command()
@commands.has_permissions(administrator= True)
async def unban(ctx, *, member):
    banned_users = await ctx.guild.bans()
    member_name, member_discriminator = member.split('#')
    for ban_entry in banned_users:
        user = ban_entry.user
        if (user.name, user.discriminator) == (member_name, member_discriminator):
            await ctx.guild.unban(user)
            await ctx.send('Пользователь успешно разбанен')
            return

@Bot.event
async def on_message( message ):
    filter = ['!leave', '!play','!skip']
    for word in filter:

            if message.content.count(word) > 0:
                print('%s bad word' % (message.author.id))
                await message.channel.purge(limit=1)
                await message.author.send('Просьба писать команды для бота в #music')
            await Bot.process_commands(message)

@Bot.event
async def on_message( message ):
    filter = ['!leave', '!play','!skip']
    for word in filter:

            if message.content.count(word) > 0:
                print('%s bad word' % (message.author.id))
                await message.channel.purge(limit=1)
                await message.author.send('Просьба писать команды для бота в #music')
            await Bot.process_commands(message)

@Bot.event
async def on_member_join(member):
    await member.create_dm()
    await member.dm_channel.send(f'Привет, {member.name}, добро пожаловать на наш сервер!')
    return

@Bot.event
async def on_ready():
    await Bot.change_presence(status=None, activity=discord.Game("Steins;Gate 0"))
    print("Bot is ready!")

@Bot.command()
@commands.has_permissions(administrator= True)
async def clear(ctx, amount=None):
    await ctx.channel.purge(limit=int(amount))
    await ctx.channel.send('Сообщения успешно удалены')

Bot.run("Token")

1 个答案:

答案 0 :(得分:1)

我很确定您运行了两次该程序,以确保不会发生这种情况,我建议实现一个kill开关,因此每次重新运行该程序时,请先在Discord上激活kill开关,然后再次运行该程序。 我制作的killswitch示例如下:

@client.command()
async def quit(ctx):
    await ctx.send("Shutting down the bot")
    return await client.logout() # this just shuts down the bot.