Discord.py-Rewrite 获取列入黑名单的术语列表并检查命令后的参数是否包含列入黑名单的术语之一

Discord.py-Rewrite Taking a list of blacklisted terms and checks if arguments after command contains one of the blacklisted terms(Discord.py-Rewrite 获取列入黑名单的术语列表并检查命令后的参数是否包含列入黑名单的术语之一) - IT屋-程序员软件开
本文介绍了Discord.py-Rewrite 获取列入黑名单的术语列表并检查命令后的参数是否包含列入黑名单的术语之一的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

限时送ChatGPT账号..

我正在开发一个类似于Discord Delivers"的不和谐机器人;和比萨饼".我正在尝试获取术语/关键字列表并检查命令后的参数(命令的代码在这篇文章的末尾);因此,如果他们执行 >order BadWord 则它会检查它是否包含先前指定的列入黑名单的术语之一,如果是,则像 await ctx.send("Due to your order contains被列入黑名单的条款之一,您的订单将不会被放置.") 或类似的东西.我很抱歉没有说出我所尝试的,正如我所能想到的那样,正在做诸如 if args in blacklist: 之类的事情,或者为每个单词做类似的事情.

I am working on a discord bot similar to "Discord Delivers" and "Pizza Byte". And I am trying to take a list of terms/keywords and check if the arguments after the command (The code for the command is at the end of this post); So if they do >order BadWord then it checks if it contains one of the previously specified blacklisted terms, and if so, does like await ctx.send("Due to your order containing one of the blacklisted terms, your order will not be placed.") Or something like that. I am sorry for not saying what i have tried, as all i can think of, is doing things like if args in blacklist: or something like that for each word.

@bot.command(pass_context=True)
async def order(ctx, *, orderItem):
    channel = bot.get_channel(CHANNEL ID OF THE CHANNEL)
    link = await ctx.channel.create_invite(max_age = 300)
    global baseNumberID
    baseNumberID += 1
    global orderIDdf
    global df
    df[str(baseNumberID)] = ctx.author.name
    embed=discord.Embed(title="New order", color=0xfc57ff)
    embed.add_field(name="Who and Where", value="{} in {} in the {} channel".format(ctx.message.author, ctx.message.guild.name, ctx.message.channel.mention), inline=False)
    embed.add_field(name="What", value="{}".format(orderItem), inline=False)
    embed.add_field(name="Invite", value="{}".format(link), inline=False)
    embed.add_field(name="Order ID", value="Order ID is {}".format(baseNumberID), inline=False)
    embed.add_field(name="Time", value="{} GM time".format(strftime("%Y-%m-%d %H:%M:%S", gmtime())), inline=True)
    embed.set_footer(text="End of this Order")
    #Second embed that will be used later.
    deliverIDInfo = str(baseNumberID)
    deliverInfoEmbed=discord.Embed(title="Order Info")
    deliverInfoEmbed.add_field(name="Who and Where", value="{} in {} in the {} channel".format(ctx.message.author, ctx.message.guild.name, ctx.message.channel.mention), inline=False)
    deliverInfoEmbed.add_field(name="What", value="{}".format(orderItem), inline=False)
    deliverInfoEmbed.add_field(name="Invite", value="{}".format(link), inline=False)
    deliverInfoEmbed.add_field(name="Order ID", value="Order ID is {}".format(baseNumberID), inline=False)
    deliverInfoEmbed.add_field(name="Time", value="{} GMT time".format(strftime("%Y-%m-%d %H:%M:%S", gmtime())), inline=True)
    deliverInfoEmbed.set_footer(text="End of this Order")
    orderIDdf[deliverIDInfo] = deliverInfoEmbed
    await ctx.author.send("Your order has been placed!")
    await ctx.author.send(embed=embed)
    await channel.send(embed=embed)

额外

如果可能的话,列入黑名单的术语可以是 json 文件还是文本文件?谢谢.

EXTRA

And if possible, could the blacklisted terms be in like either a json file or a text file? Thanks.

我想我应该澄清一下,我确实定义了所使用的变量.一切正常.

I thought i should clarify that I do in fact define the variables that are used. Everything works properly.

推荐答案

  • 没有 json 库:
  • blacklist = ['test', 'yolo'] #Your blacklisted words here
    @bot.command(pass_context=True)
    async def order(ctx, *, orderItem):
        if orderItem.lower() in blacklist:
            await ctx.send("Due to your order containing one of the blacklisted terms, your order will not be placed.")
        else:
            #Your code here
    

    • 使用 json 库:
    • json 文件(将包含所有列入黑名单的单词)

      The json file (which will contain every blacklisted words)

      ['test', 'yolo']
      

      from json import loads
      
      @bot.command(pass_context=True)
      async def order(ctx, *, orderItem):
          with open('blacklist.txt', 'r') as file:
              blacklist = loads(file.read())
          if orderItem.lower() in blacklist:
              await ctx.send("Due to your order containing one of the blacklisted terms, your order will not be placed.")
          else:
              #Your code here
      

      这篇关于Discord.py-Rewrite 获取列入黑名单的术语列表并检查命令后的参数是否包含列入黑名单的术语之一的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

      本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

How do I make a list of all members in a discord server using discord.py?(如何使用 discord.py 列出不和谐服务器中的所有成员?)
how to change discord.py bot activity(如何更改 discord.py 机器人活动)
Issues with getting VoiceChannel.members and Guild.members to return a full list(让 VoiceChannel.members 和 Guild.members 返回完整列表的问题)
Add button components to a message (discord.py)(将按钮组件添加到消息(discord.py))
on_message() and @bot.command issue(on_message() 和@bot.command 问题)
How to edit a message in discord.py(如何在 discord.py 中编辑消息)