【问题标题】:How to make a discord bot kick someone when they say a trigger word当他们说出触发词时,如何让不和谐的机器人踢某人
【发布时间】:2021-06-08 14:33:50
【问题描述】:

如何让 Discord 机器人在某人说出触发词时踢他们?例如,当有人说“白痴”时,他们会被踢出服务器。

这是我尝试过的:

**import discord
import time
from discord.ext import commands

client = discord.Client()

@client.event
async def on_ready():
    print("Bot is ready?")

@client.event
async def on_message(message):
    if message.content.find("lol") != -1:
        await message.channel.send("HI!")

@client.event
async def on_message(message):
    if message.content.find('matei') != -1:
        await kick('minionulLuiMatei#5893')
        return




client.run(token)**

【问题讨论】:

    标签: python discord discord.py


    【解决方案1】:

    不能拥有多个on_message 事件。您必须将它们合二为一。

    一篇解释得很好的帖子:Why multiple on_message events will not work

    现在回答你的问题。您可以使用两种方法过滤单词并踢出成员:

    第一种方法:过滤所有消息并查看单词Idiot是否出现在句子中的任何位置。

    async def on_message(message):
        if "Idiot" in message.content:
    

    第二种方法: 检查单词 Idiot 是否只出现在句子的开头。

    async def on_message(message):
        if message.content.startswith("Idiot"):
    

    然后要踢一个成员,你使用以下函数:

    await message.author.kick(reason=None)
    

    您的整个代码将是:

    @client.event
    async def on_message(message):
        if "Idiot" in message.content: # Method 1
            await message.author.kick(reason=None) # Kick the author of the message, reason is optional
    
        if message.content.startswith("Idiot"): # Method 2
           await message.author.kick(reason=None)
    

    【讨论】:

      猜你喜欢
      • 2020-03-26
      • 2020-09-23
      • 2021-06-08
      • 2019-02-22
      • 1970-01-01
      • 2020-12-30
      • 2021-08-17
      • 2020-11-18
      • 1970-01-01
      相关资源
      最近更新 更多