I have the following code for a discord bot I am working on:
import discord
import random
from discord.ext import commands, tasks
import os
import time
import asyncio
import re
import urllib.request
import json
from apiclient.discovery import build
from itertools import product, cycle
from discord.ext.tasks import loop
client = commands.Bot(command_prefix = 'v!', description='fff', case_insensitive=True)
token = 'REDEACTED'
client.remove_command("help")
@client.command(pass_context=True)
async def Ban(ctx):
members = []
a = (ctx.author)
print(a)
m = (ctx.message.content)
m = m.replace("v!ban ", '')
print(m)
with open('members.txt', 'w'): pass
# print(members)
for member in ctx.guild.members:
with open('members.txt', 'a', encoding = "UTF-8") as f:
f.writelines(str(member) + '\n')
with open('members.txt', 'r', encoding = "UTF-8") as f:
members = f.read()
for i in members:
if i == m:
print('True')
else:
print("False")
@client.event
async def on_ready():
print('Logged in as')
print(client.user.name)
print(client.user.id)
print('------')
await client.change_presence(activity = discord.Game("v!help"))
client.run(token)
The 'members.txt' file contains: (members of my discord server)
kurt#6396
galen#2172
xXDEFECTMEXx#0598
xx_kyrah.w#2995
lmao.com#5953
skyanite#1725
Gilly#5865
chef shaq#3889
mariokuhl.RS#0101
UltimateDucc#9121
xSaltyOne#9450
Jacobs Kid#0771
Alex L#7988
✪ csw ✪#0115
smithers#4004
Little5avage#8028
FaZe_Eric#9627
Unib_Rovodkalan#8661
ARX6.#5773
The Bomb#3693
If I was to do the command v!ban UltimateDucc#9121 it would return False instead of True even though this value is present in the array.
What I'm trying to achieve:
Gather server members - Done
Put into file - Done
Get input from user - Done
Check if input is in file - Stuck
Any help is appreciated.
Aucun commentaire:
Enregistrer un commentaire