【发布时间】:2021-07-27 12:08:14
【问题描述】:
您好,我尝试了很多命令来修复它,但机器人什么也没做 这是我的代码。文件是 bot.py
import discord
import os
from discord.ext import commands
class MyClient(discord.Client):
async def on_ready(self):
print('Logged on as {0}!'.format(self.user))
async def on_message(self, message):
print('Message from {0.author}: {0.content}'.format(message))
client = MyClient()
@client.event
async def on_ready():
print(f'{client.user.name} Test!')
###############
bot = commands.Bot(command_prefix="!")
@bot.event
async def on_guild_join(guild):
if guild.system_channel:
await guild.system_channel.send("Test")
#@client.event
#async def on_member_join(member):
# await ctx.author.send("Welcome!")
##*@client.event
#async def on_member_join(member):
# await member.create_dm()
# await member.send(
# f'Hallo{member.name}, Willkommen'
# )
为什么它不起作用我尝试了很多命令/模型。 我使用 Notepad++ 进行编程。给它一个更好的程序来用 Python 编程?初学者应该怎么做?
【问题讨论】:
-
试试 PyCharm、Visual Studio Code 或类似的东西。你启用了 Intent 吗?
-
好的,谢谢,不,但我现在添加```intents = discord.Intents.default() intents.members = True client = commands.Bot(command_prefix=',', intents=intents) ``` 但仍然无法正常工作:/
-
您是否尝试过使用
print声明?比如:print(f"Joined {guild}.")看看这个事件是否有效? -
@Dominik 它仍然无法正常工作查看第二个答案中的代码:(。我也尝试打印:/
标签: python discord.py