Discord bot发送2条消息,而不是1条消息 [英] Discord bot sends 2 messages instead of 1
本文介绍了Discord bot发送2条消息,而不是1条消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的机器人响应我的命令发送了两次相同的消息。
My bot is sending the same message twice, in response to my command.
请帮助我,我不知道该怎么办
Please help me, I don't know what to do with this problem
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")
推荐答案
我很确定您运行了该程序两次,以确保不会发生这种情况,我建议实施一个kill开关,这样,每次您重新运行该程序时,都首先在Discord上激活kill开关,然后再次运行该程序。
我执行的killswitch示例如下:
I'm pretty sure you ran the program twice, to make sure this doesn't happen, I suggest implementing a kill switch so every time when you rerun the program you activate the kill switch first on Discord then run the program again. An example of the killswitch that I made is something like this:
@client.command()
async def quit(ctx):
await ctx.send("Shutting down the bot")
return await client.logout() # this just shuts down the bot.
这篇关于Discord bot发送2条消息,而不是1条消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文