使用client.user.edit(nick=name)
时,僵尸程序的昵称不会更改,但可以正确执行先前的命令和随后的命令。我应该使用其他命令还是参数不正确?
我正在使用Discord.py-rewrite,并成功将client.user.edit(username=name)
设置为username
到name
,但这不是我想要的。我需要更改昵称以避免更改用户名时出现混乱的情况。
def function(name):
await client.user.edit(nick=name)
应该像更改用户名一样更改昵称,但是什么也没有发生。我也没有收到错误。我已将漫游器角色权限更改昵称并将管理昵称设置为true。
答案 0 :(得分:0)
等待message.guild.get_member(self.user.id).edit(nick = name)
获取已发送消息的公会,并编辑bot成员的昵称。
答案 1 :(得分:0)
import discord
import time
import asyncio
messages = joined = 0
def read_token():
with open("token.txt", "r") as f:
lines = f.readlines()
return lines[0].strip()
token = read_token()
client = discord.Client()
async def update_stats():
await client.wait_until_ready()
global messages, joined
while not client.is_closed():
try:
with open("stats.txt", "a") as f:
f.write(f"Time: {int(time.time())}, Messages: {messages}, Members Joined:
{joined}\n")
messages = 0
joined = 0
await asyncio.sleep(5)
except Exception as e:
print(e)
await asyncio.sleep(5)
@client.event
async def on_member_update(before, after):
n = after.JOHN
if n:
if n.lower().count("tim") > 0:
last = before.nick
if last:
await after.edit(nick=JOHN)
else:
await after.edit(nick="COOKIES")
@client.event
async def on_member_join(member):
global joined
joined += 1
for channel in member.server.channels:
if str(channel) == "general":
await channel.send(f"""Welcome to the server {member.mention}""")
@client.event
async def on_message(message):
global messages
messages += 1
id = client.get_guild(ID HERE)
channels = ["commands"]
valid_users = ["JOHN#1234"]
bad_words = ["bad", "stop", "45"]
for word in bad_words:
if message.content.count(word) > 0:
print("A bad word was said")
await message.channel.purge(limit=1)
if message.content == "!help":
embed = discord.Embed(title="Help on BOT", description="Some useful commands")
embed.add_field(name="!hello", value="Greets the user")
embed.add_field(name="!users", value="Prints number of users")
await message.channel.send(content=None, embed=embed)
if str(message.channel) in channels and str(message.author) in valid_users:
if message.content.find("!hello") != -1:
await message.channel.send("Hi")
elif message.content == "!users":
await message.channel.send(f"""# of Members: {id.member_count}""")
client.loop.create_task(update_stats())
client.run(token)