저는 "Discord Delivers"및 "Pizza Byte"와 유사한 불화 봇을 작업 중입니다. 그리고 용어 / 키워드 목록을 가져 와서 명령 뒤에 나오는 인수가 있는지 확인하려고합니다 (명령에 대한 코드는이 게시물의 끝에 있습니다). 그래서 그들이 >order BadWord
있다면 그것은 이전에 지정된 블랙리스트 용어 중 하나가 포함되어 있는지 확인하고, 그렇다면 await ctx.send("Due to your order containing one of the blacklisted terms, your order will not be placed.")
Or와 같은 것입니다. 제가 생각할 수있는 모든 일 if args in blacklist:
을 각 단어에 대해 그런 식으로하는 것 뿐입니다.
@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 파일이나 텍스트 파일과 같은 형태 일 수 있습니까? 감사.
실제로 사용되는 변수를 정의한다는 것을 명확히해야한다고 생각했습니다. 모든 것이 제대로 작동합니다.
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 파일 (블랙리스트에있는 모든 단어가 포함됨)
['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
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다