简体   繁体   English

Discord 机器人删除用户的所有消息

[英]Discord bot which deletes all messages from user

I would like to write a code for a bot which will delete all messages from a person who leaves the server.我想为一个机器人编写代码,它将删除离开服务器的人的所有消息。 Bot will ban him and delete messages. Bot 将禁止他并删除消息。 Do you have any suggestions what's wrong?:)你有什么建议吗?:)

This is the code:这是代码:

import discord

client = discord.Client

@client.event
async def on_member_remove(member: discord.Member):
  await member.ban()

Error:错误:

Traceback (most recent call last):
  File "main.py", line 6, in <module>
    async def on_member_remove(member: discord.Member):
TypeError: event() missing 1 required positional argument: 'coro'

EDIT:编辑:

I have fixed it and now code is like:我已经修好了,现在代码是这样的:

import discord
import os

client = discord.Client()

@client.event
async def on_ready():
    print('We have logged in as {0.user}'.format(client))

@client.event
async def on_member_remove(member: discord.Member):
  await member.ban()

client.run(os.getenv('DISCORD_TOKEN'))

I use replit to make my code.我使用 replit 来制作我的代码。 Bot works it is online but it doesn't ban or do anything with the user. Bot 在网上工作,但它不会禁止用户或对用户做任何事情。 Have you got idea why?你知道为什么吗?

I have also file ".virtualenv" and as well main.py我还有文件“.virtualenv”和 main.py

Found this issue on GitHub, it seems to be the same error the you're having.在 GitHub 上发现了这个问题,它似乎与您遇到的错误相同。

The issue is that you're not initializing the client variable as an instance of the discord.Client class but rather assigning the class to the client variable.问题是您没有将客户端变量初始化为discord.Client class 的实例,而是将 class 分配给客户端变量。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM