无法使用 discord.py 服务器将某人静音

时间:2021-04-08 07:31:16

标签: python discord discord.py

基本上每当我运行这段代码时,它都会给我一个错误,我试图让代码服务器每 20 秒让我的一个朋友静音 5 秒,它说定义用户的行有问题.

import discord
from discord.ext import commands
from discord.ext import commands, tasks
import random
import datetime
from datetime import date
import calendar
import time
import asyncio
from discord.ext.tasks import loop


client = commands.Bot(command_prefix='.')


@tasks.loop(seconds=20)
async def mute_person():
  user = await discord.Guild.fetch_member("670549896247509002", "670549896247509002")  # Get the Member Object
  await user.edit(mute=True)  # Mute
  await asyncio.sleep(20)  # Waits for 20 seconds then unmute.
  await user.edit(mute=False)  # Unmute

@client.event
async def on_ready():
  print("I am ready")
  mute_person.start()


client.run("Token")

1 个答案:

答案 0 :(得分:0)

您没有使用正确的函数 discord.Guild 不存在,因为您正在使用它。主要用途必须是 await guild.fetch_member(member_id) 然后 guild 表示具有特定 ID 的公会对象。所以你需要先获得公会。