英文:
Discord.py recognizing on_message client event, but IF statements not responding
问题
if p_message.content == "roll":
return str(random.randint(1, 6))
英文:
I am working on a Discord bot and in this case want the bot to roll a 6 sided die when any user gives the "roll" command. See code below. Oddly enough this was working just fine, but now the print(worked)
triggers and the if p_message
statements do nothing. I get no errors, it just doesn't work.
import discord
import random
intents = discord.Intents.all()
intents.message_content = True
client = discord.Client(intents=intents)
@client.event
async def on_message(message):
p_message = message
print("worked")
if p_message == "roll":
return str(random.randint(1, 6))
client.run('***') #my token
I have tried ensuring that message
is a str
but it makes no difference. Again, this code worked previously (at 1am when I was probably too tired to be writing code) and throws no error. It just doesn't respond to the command at all in discord.
答案1
得分: 1
import discord
import random
# 将 .all 更改为 .default
intents = discord.Intents.default()
intents.message_content = True
client = discord.Client(intents=intents)
@client.event
async def on_message(message):
# 使用 message.content
if message.content == "roll":
# 向频道发送消息,说明有人输入了“roll”
await message.channel.send(random.randint(1, 6))
client.run('***') # 我的令牌
英文:
import discord
import random
# change .all to .default
intents = discord.Intents.default()
intents.message_content = True
client = discord.Client(intents=intents)
@client.event
async def on_message(message):
# use message.content
if message.content == "roll":
# send message to the channel that someone types "roll"
await message.channel.send(random.randint(1, 6))
client.run('***') # my token
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论